Jump to content

User:Shushugah/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Shushugah (talk | contribs) at 00:18, 17 July 2021 (Add source link button that excludes navboxes, via solution at User:PrimeHunter/Source links.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
importScript('User:Kephir/gadgets/sagittarius.js'); // [[User:Kephir/gadgets/sagittarius]]

/* 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.
   To use the script, add the following line to Special:MyPage/common.js:
 
importScript('User:PrimeHunter/Source links.js'); // Linkback: [[User:PrimeHunter/Source links.js]]

*/

mw.loader.using(['mediawiki.util'], function () {
  var name = mw.config.get( 'wgPageName' ).replace("Special:WhatLinksHere/", "");
  var url;
  try {
      url = mw.util.getUrl( 'Special:Search' ) + '?profile=all&search=' +
      encodeURIComponent('linksto:"' + name + '" ' + 'insource:"' + name + '" ' +
      'insource:/\\[\\[:?[' + name[0] + name.charAt(0).toLowerCase() + ']' +
      name.substring(1).replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&') + '[\\]\\|#]/' ).replace(/_/g, " ");
  } catch(e) {
      url = '#error'; // EXAMPLE URL: https://en.wikipedia.org/w/index.php?title=%F0%9F%91%A9%F0%9F%8F%BF&action=history
  }
  mw.util.addPortletLink(
    'p-tb',
    url,
    'Source links',
    'pt-sourcelinks',
    'What links here in the source',
    null,
    '#t-recentchangeslinked'
  );
});