Jump to content
Wikipedia The Free Encyclopedia

User:Polygnotus/Scripts/PreviousDiscussions.js

From Wikipedia, the free encyclopedia
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:Polygnotus/Scripts/PreviousDiscussions.
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.
 //Adds "Previous Discussions" link to the More menu when looking at someone's talkpage. 
 //When you click it both the subpages of their talkpage and userpage get searched for your username 
 //(Some people put their talkpage archives as subpages of their userpage). 
 (function(){
 'use strict';

 // Check if we're on a user talk page
 if(mw.config.get('wgNamespaceNumber')!==3){
 return;// Exit if not on a user talk page
 }

 // Get the current user's username
 varcurrentUser=mw.config.get('wgUserName');

 // Exit if user is not logged in
 if(!currentUser){
 return;
 }

 // Get the username from the user talk page
 varpageName=mw.config.get('wgPageName');
 vartalkPageOwner=pageName.replace('User_talk:','');

 // Decode the username in case it contains special characters
 talkPageOwner=decodeURIComponent(talkPageOwner);

 // Encode the current user with quotes for exact phrase search
 varquotedCurrentUser='"'+currentUser+'"';
 varencodedQuotedCurrentUser=encodeURIComponent(quotedCurrentUser);
 varencodedTalkPageOwner=encodeURIComponent(talkPageOwner);

 // Construct the search URL using subpageof: operator
 // This searches for "currentUser" subpageof:"talkPageOwner" in both User (ns2) and User talk (ns3) namespaces
 varsearchQuery=encodedQuotedCurrentUser+'+subpageof%3A%22'+encodedTalkPageOwner+'%22';
 varsearchUrl='https://en.wikipedia.org/w/index.php?search='+searchQuery+
 '&title=Special%3ASearch&profile=advanced&fulltext=1&ns2=1&ns3=1';

 // Add the portlet link
 $(document).ready(function(){
 mw.util.addPortletLink(
 'p-cactions',// Add to the "More" dropdown menu
 searchUrl,// URL
 'Previous Discussions',// Link text
 'ca-search-archives',// Link ID
 'Search '+talkPageOwner+'\'s archives for mentions of '+currentUser,// Tooltip
 null,// Access key (null for none)
 '#ca-history'// Insert before the history tab
 );
 });
 })();

AltStyle によって変換されたページ (->オリジナル) /