Jump to content
Wikipedia The Free Encyclopedia

User:Polygnotus/Scripts/WikiBlame.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.
Documentation for this user script can be added at User:Polygnotus/Scripts/WikiBlame.
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.
 // WikiBlame Tool for Wikipedia articles with hotkey support
 (function(){
 // Only run on article pages (not special pages, talk pages, etc.)
 if(!mw.config.get('wgIsArticle')){
 return;
 }

 // Function to perform WikiBlame search
 functionperformWikiBlameSearch(){
 // Get selected text
 constselectedText=window.getSelection().toString().trim();

 if(!selectedText){
 alert('Please select text first (then use Ctrl+Shift+L or the Tools menu)');
 return;
 }

 // Get current language and article information from MediaWiki
 constlang=mw.config.get('wgContentLanguage');// e.g., 'en', 'de', 'fr'
 constarticleTitle=mw.config.get('wgPageName');// Already URL-encoded by MediaWiki

 // URL encode the selected text for the needle parameter
 constencodedNeedle=encodeURIComponent(selectedText);

 // Construct the WikiBlame URL
 constwikiblameUrl=`https://wikipedia.ramselehof.de/wikiblame.php?user_lang=${lang}&lang=${lang}&project=wikipedia&tld=org&article=${articleTitle}&needle=${encodedNeedle}`;

 // Open WikiBlame in a new tab/window
 window.open(wikiblameUrl,'_blank');
 }

 // Wait for the page to be fully loaded
 mw.loader.using(['mediawiki.util']).then(function(){
 // Add the WikiBlame link to the Tools menu
 mw.util.addPortletLink(
 'p-tb',// Tools menu ID
 '#',// href (we'll handle the click with JavaScript)
 'WikiBlame search',// link text
 't-wikiblame',// link ID
 'Search for when selected text was added to this article (Ctrl+Shift+L)'// tooltip with hotkey info
 );

 // Add click handler for the menu item
 document.getElementById('t-wikiblame').addEventListener('click',function(e){
 e.preventDefault();
 performWikiBlameSearch();
 });

 // Add keyboard shortcut handler
 document.addEventListener('keydown',function(e){
 // Check for Ctrl+Shift+L (case-insensitive)
 if(e.ctrlKey&&e.shiftKey&&(e.key==='L'||e.key==='l')){
 e.preventDefault();// Prevent any default browser behavior
 performWikiBlameSearch();
 }
 });
 });
 })();

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