Jump to content

User:Þjarkur/Source links.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
Copied from [[User:PrimeHunter/Source links.js]] 


This script adds "Source links" below "What links here" in the sidebar.
   "What links here" will include pages using a template with the link.
   "Source links" tries to search for pages where the link is in the source.

*/

mw.loader.using(['mediawiki.util'], function () {
  var name = mw.config.get( 'wgPageName' ).replace("Special:WhatLinksHere/", "");
  mw.util.addPortletLink(
    'p-tb',
    mw.util.getUrl( 'Special:Search' ) + '?profile=advanced&ns0=1&ns10=1&sort=relevance&search=' + 
    encodeURIComponent('linksto:"' + name + '" ' + 'insource:"' + name + '" ' +
    'insource:/\\[\\[:?[' + name[0] + name.charAt(0).toLowerCase() + ']' +
    name.substring(1).replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&') + '[\\]\\|#]/' ).replace(/_/g, " "),
    'Source links',
    'pt-sourcelinks',
    'What links here in the source',
    null,
    '#t-recentchangeslinked'
  );
});