User:Hoo man/useful links.js
Appearance
From Meta, a Wikimedia project coordination wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/** * [[m:user:Hoo man]]; Version 3.3; 2023年05月18日; * Gives some useful links on user, user talk and user contribution pages * Tested in IE and FF with vector and monobook, uses my (Hoo man) wiki tools (shared.js) * * DO NOT COPY AND PASTE, instead see https://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/Useful_links */ /*global hoo, mw, usefulLinksConfig, usefulLinksTools, usefulLinksUserTools, usefulLinksIpTools, disable_useful_links */ /*jshint forin:false, noarg:true, noempty:true, eqeqeq:true, loopfunc:true, bitwise:true, undef:true, browser:true, jquery:true, indent:4, maxerr:50, white:false, esversion: 6 */ mw.loader.using(['mediawiki.util'],function(){ "use strict"; // Default config, overwrite using 'usefulLinksConfig' varconfig={ useFoldedMenu:true }, tools,userTools,ipTools; /** Default tools: To add a tool in you personal js just do the same as below, but replace the "blah." out of the variable names, with the ones given in the comments. To remove one, just set them to null. Example: if ( typeof usefulLinksUserTools === 'undefined' ) usefulLinksUserTools = {}; //user only tools usefulLinksUserTools.xEditCounter = null; to disable X!'s edit counter (1ドル: username - 2ドル: lang code - 3ドル: wiki code - 4ドル: server address + script path) **/ // Tools for all users (can be overwritten using usefulLinksTools instead of tools in your own JS) // Global contribs tools={ // Global contribs globalContribs:{ url:'//tools.wmflabs.org/guc/?user=1ドル', linkText:'Global contribs' }, // (local) contribs contribs:{ url:mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace('1ドル','Special:Contributions/')+'1ドル', linkText:'Contributions' } }; // User tools for all logged-in users (can be overwritten using usefulLinksUserTools instead of userTools in your own JS) userTools={ // Central Auth ca:{ url:'//meta.wikimedia.org/wiki/Special:CentralAuth/1ドル', linkText:'CentralAuth' }, // X!'s edit counter xEditCounter:{ url:'//tools.wmflabs.org/xtools/pcount/index.php?name=1ドル&lang=2ドル&wiki=3ドル', linkText:'X!\'s tool' }, // User rights userRights:{ url:'4ドル?title=Special:ListUsers&limit=1&username=1ドル', linkText:'Rights' } }; // IP tools for all logged-out users (can be overwritten using usefulLinksIpTools instead of ipTools in your own JS) ipTools={ // Whois whois:{ url:'https://whois-referral.toolforge.org/gateway.py?lookup=true&ip=1ドル', linkText:'Whois' } }; functioninit(){ vartoolURI,username,i,lang; if(typeofdisable_useful_links!=='undefined'&&disable_useful_links){ returnfalse; } // Custom config if(typeofusefulLinksConfig!=='undefined'){ if(typeofusefulLinksConfig.toolLinkMethod!=='undefined'&&usefulLinksConfig.toolLinkMethod!=='toolbar'){ // Disable folded menus if the user selected another link method than toolbar if(typeofusefulLinksConfig.toolLinkMethod==='undefined'||usefulLinksConfig.useFoldedMenu!==true){ // But only if he/she didn't explicitly enable it config.useFoldedMenu=false; } } $.extend(config,usefulLinksConfig); } // i18n if(config.lang){ lang=config.lang; }else{ lang=hoo.config.lang; } if(lang==='de'){ mw.messages.set('hoo-usefulLinks-toolbarText','Nützliche Links'); }else{ mw.messages.set('hoo-usefulLinks-toolbarText','Useful links'); } if(typeofusefulLinksTools!=='undefined'){ $.extend(tools,usefulLinksTools); } if(typeofusefulLinksUserTools!=='undefined'){ $.extend(userTools,usefulLinksUserTools); } if(typeofusefulLinksIpTools!=='undefined'){ $.extend(ipTools,usefulLinksIpTools); } if(typeofconfig.toolLinkMethod==='undefined'){ config.toolLinkMethod=hoo.config.toolLinkMethod; } // Get user name if(mw.config.get('wgCanonicalNamespace')==='User'||mw.config.get('wgCanonicalNamespace')==='User_talk'){ // User or user talk page username=mw.config.get('wgTitle').match(/([^\/]+)/)[1]; }elseif(mw.config.get('wgCanonicalNamespace')==='Special'&&mw.config.get('wgCanonicalSpecialPageName')==='Contributions'){ // Special:Contributions if(window.location.href.indexOf('&')===-1){ // Request like Special:Contributions/Username username=mw.config.get('wgTitle').substring(mw.config.get('wgTitle').lastIndexOf('/')+1); }else{ username=mw.util.getParamValue('target'); } // We're already on the contribs page tools.contribs=null; }else{ return; } if(!mw.util.isIPv4Address(username)&&!mw.util.isIPv6Address(username)){ // Registered user $.extend(tools,userTools); }else{ $.extend(tools,ipTools); } if(config.useFoldedMenu&&config.toolLinkMethod==='toolbar'){ // Create parent for folded menu hoo.addToolLink( mw.messages.get('hoo-usefulLinks-toolbarText'), function(){returnfalse;}, 'usefulLinksMenu', 'toolbar' ); } constwgServerParts=mw.config.get('wgServer').split('.'), wikiName=wgServerParts[0].replace(/(https?)?\/\//,''), wikiFamily=wgServerParts[1]; // Add links for(iintools){ if(tools[i]===null||typeoftools[i].url==='undefined'){ continue; } toolURI=tools[i].url .replace(/\1ドル/g,username) .replace(/\2ドル/g,wikiName) .replace(/\3ドル/g,wikiFamily) .replace(/\4ドル/g,mw.config.get('wgServer')+mw.config.get('wgScript')); if(config.useFoldedMenu&&config.toolLinkMethod==='toolbar'){ try{ hoo.addSubLink( 'usefulLinksMenu', tools[i].linkText, toolURI ); }catch(e){ mw.log.warn('Problem adding link'); } }else{ hoo.addToolLink( tools[i].linkText, toolURI, '', config.toolLinkMethod ); } } } // Load the shared functions script if needed if(typeofhoo==='undefined'||typeofhoo.addToolLink==='undefined'){ $.ajax({ url:'//meta.wikimedia.org/w/index.php?title=User:Hoo_man/functions.js&action=raw&ctype=text/javascript', dataType:'script', cache:true }) .done( function(){ $(document).ready(init); } ); }else{ $(document).ready(init); } });