User:Melecie/yournav.js

/*************************************************************************************************** * yournav: Customizable navigation portlets **************************************************************************************************/ // referenceable array for modified portlets var modifiedPortletsArr = []; // lookup table for links // links consist of arrays with data to be plugged into addLink const links = { main_page: ["Main Page", "Main page"], contents: "Wikipedia:Contents", current_events: "Wikipedia:Current events", random: ["Special:Random", "Random article"], about: ["Wikipedia:About", "About Wikipedia"], contact_us: "Wikipedia:Contact us", mos: "Wikipedia:Manual of Style", itn_candidates: ["Wikipedia:In the news/Candidates", "In the news candidates"], dyk_candidates: ["Template talk:Did you know", "Did you know candidates"], signpost: ["Wikipedia:Wikipedia Signpost", "The Signpost"], teahouse: "Wikipedia:Teahouse", help_desk: "Wikipedia:Help Desk", ref_desk: "Wikipedia:Reference desk", editor_homepage: ["Special:Homepage", "Editor homepage"], mentor_dashboard: "Special:Mentor dashboard", task_center: "Wikipedia:Task center", village_pump: "Wikipedia:Village pump", vp_policy: "Wikipedia:Village pump (policy)", vp_technical: "Wikipedia:Village pump (technical)", vp_proposals: "Wikipedia:Village pump (proposals)", vp_idea_lab: "Wikipedia:Village pump (idea lab)", vp_wmf: "Wikipedia:Village pump (WMF)", vp_miscellaneous: "Wikipedia:Village pump (miscellaneous)", coi_er: ["User:AnomieBOT/SPERTable", "CoI edit requests"], pb_er: ["User:AnomieBOT/SPERTable", "Partial block edit requests"], sper: ["User:AnomieBOT/SPERTable", "Semi-protected edit requests"], eper: ["User:AnomieBOT/EPERTable", "Extended-protected edit requests"], tper: ["User:AnomieBOT/TPERTable", "Template-protected edit requests"], per: ["User:AnomieBOT/PERTable", "Protected edit requests"], iper: ["User:AnomieBOT/IPERTable", "Interface-protected edit requests"], an: ["Wikipedia:Administrator's noticeboard", "AN"], ani: ["Wikipedia:Administrator's noticeboard/Incidents", "AN/I"], ufaa: ["Wikipedia:Usernames for administrator attention", "UFAA"], aiv: ["Wikipedia:Administrator intervention against vandalism", "AIV"], rfa: "Wikipedia:Requests for adminship", afd: "Wikipedia:Articles for deletion", afd_today: ["Wikipedia:Articles for deletion/Log/Today", "AfD today"], tfd: "Wikipedia:Templates for deletion", tfd_today: ["Wikipedia:Templates for deletion/Log/Today", "TfD today"], ffd: "Wikipedia:Files for deletion", ffd_today: ["Wikipedia:Files for deletion/Today", "FfD today"], cfd: "Wikipedia:Categories for deletion", cfd_today: ["Wikipedia:Categories for deletion/Log/Today", "CfD today"], rfd: "Wikipedia:Redirects for deletion", rfd_today: ["Wikipedia:Redirects for deletion/Log/Today", "RfD today"], mfd: "Wikipedia:Miscellany for deletion", google: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://www.google.com/search?as_eq=wikipedia&q="' + mw.config.get('wgTitle') + '"', "Google", "mel-google"); }	},	bing: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://www.bing.com/search?q="' + mw.config.get('wgTitle') + '" -wikipedia', "Bing", "mel-bing"); }	},	ddg: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://duckduckgo.com/?q="' + mw.config.get('wgTitle') + '" -wikipedia', "DuckDuckGo", "mel-ddg"); }	},	google_books: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://www.google.com/search?tbs=bks:1&q="' + mw.config.get('wgTitle') + '" -wikipedia', "Google Books", "mel-google_books"); }	},	google_news: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://www.google.com/search?tbs=nws:1&q="' + mw.config.get('wgTitle') + '" -wikipedia', "Google News", "mel-google_news"); }	},	google_scholar: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://scholar.google.com/scholar?q="' + mw.config.get('wgTitle') + '"', "Google Scholar", "mel-google_scholar"); }	},	jstor: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://www.jstor.org/action/doBasicSearch?Query="' + mw.config.get('wgTitle') + '"&acc=on&wc=on', "JSTOR", "mel-jstor"); }	},	twl: function(p) { if (["", "Draft", "User"].includes(mw.config.get('wgCanonicalNamespace'))) { mw.util.addPortletLink(p, 'https://wikipedialibrary.wmflabs.org/search/?q="' + mw.config.get('wgTitle') + '"', "The Wikipedia Library", "mel-twl"); }	},	links_here: function(p) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:WhatLinksHere/' + mw.config.get('wgRelevantPageName'), "What links here", "mel-links_here"); },	related_changes: function(p) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:RecentChangesLinked/' + mw.config.get('wgRelevantPageName'), "Related changes", "mel-related_changes"); },	permanent_link: function(p) { if (mw.config.get("wgIsArticle")) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/w/index.php?title=' + mw.config.get('wgRelevantPageName') + '&oldid=' + mw.config.get("wgCurRevisionId"), "Permanent link", "mel-permalink"); }	},	page_information: function(p) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/w/index.php?title=' + mw.config.get('wgRelevantPageName') + '&action=info', "Page information", "mel-page_information"); },	contributions: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:Contributions/' + mw.config.get('wgRelevantUserName'), "User contributions", "mel-contributions"); }	},	user_logs: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:Log/' + mw.config.get('wgRelevantUserName'), "User logs", "mel-user_logs"); }	},	mute: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:Mute/' + mw.config.get('wgRelevantUserName'), "User contributions", "mel-contributions"); }	},	user_groups: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:UserRights/' + mw.config.get('wgRelevantUserName'), "View user groups", "mel-user_groups"); }	},	blocks: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/w/index.php?title=Special:Log/block&page=' + mw.config.get('wgPageName'), "View blocks", "mel-blocks"); }	},	user_uploads: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:ListFiles/' + mw.config.get('wgRelevantUserName'), "User uploads", "mel-uploads"); }	},	user_global: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:CentralAuth/' + mw.config.get('wgRelevantUserName'), "Global account information", "mel-user_global"); }	},	filter_log: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/w/index.php?title=Special:AbuseLog&wpSearchUser=' + mw.config.get('wgRelevantUserName'), "Filter log", "mel-filter_log"); }	},	subpages: function(p) { mw.util.addPortletLink(p, 'https://en.wikipedia.org/wiki/Special:PrefixIndex/' + mw.config.get('wgRelevantPageName'), "Subpages", "mel-subpages"); },	edit_counter: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://xtools.wmcloud.org/ec/en.wikipedia.org/' + mw.config.get('wgRelevantUserName'), "Edit counter", "mel-edit_counter"); }	},	pages_created: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://xtools.wmcloud.org/pages/en.wikipedia.org/' + mw.config.get('wgRelevantUserName'), "Pages created", "mel-pages_created"); }	},	summary_search: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://sigma.toolforge.org/summary.py?name=' + mw.config.get('wgRelevantUserName'), "Edit summary search", "mel-summary_search"); }	},	global_contribs: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://guc.toolforge.org/?by=date&user=' + mw.config.get('wgRelevantUserName'), "Global contributions", "mel-global_contribs"); }	},	global_log: function(p) { if (["User", "User talk"].includes(mw.config.get("wgCanonicalNamespace"))) { mw.util.addPortletLink(p, 'https://meta.wikimedia.org/w/index.php?title=Special:Log&type=globalauth&user=&page=User:' + mw.config.get('wgRelevantUserName') + '@global', "Global log", "mel-global_log"); }	},	print: function(p) { mw.util.addPortletLink(p, "javascript:print", "Print", "mel-print"); } };

class ModifiedPortlet { constructor(name) { if (["personal", "namespaces", "views", "cactions", "search", "logo", "coll-print-export", "wikibase-otherprojects", "lang"].includes(name)) { throw new Error("Attempting to modify an invalid existing portlet"); }		this.name = name; name = "p-" + name; $("#" + name).find("li").hide; modifiedPortletsArr.push(this); }	addLink(link) { if (link in links) { link = links[link]; } else { if (typeof link == "function") { // do not accept manually written functions apart from what is already written here // maybe not a perfect fix for injections, but idk how to fully prevent them :/ return; }		}		// switch based on what kind of link is fed to the system switch (typeof link) { case "string": // basic links this.addBasicLink(link); break; case "function": // custom functions link("p-" + this.name); break; case "object": // arrays; link and label pairs this.addBasicLink(link[0], link[1]); break; }	}	addBasicLink(name, label=name.replace(/[A-Za-z ]*:/, ""), node=null) { mw.util.addPortletLink(			"p-navigation",			"https://en.wikipedia.org/wiki/" + name.replace(" ", "_"),			label,			"mel-" + name.toLowerCase.replace(" ", "-"),			null,			null,			node		); } }

// debug new ModifiedPortlet("navigation"); modifiedPortletsArr[0].addLink("subpages");