User:Gifted9/common.js: Difference between revisions
Content added Content deleted
(wikia:dev:CodeLinksDropdown, maybe) |
(rm massrename from fandom - too many dependencies, use the user:boper911/autohotkey script instead) Tag: Manual revert |
||
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
// javascript wiki browser: autowikibrowser but slightly uglier and in-browser, for when i'm not on my home computer |
|||
//jwb |
|||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript'); |
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript'); |
||
// add somewhat sensitive stuff to my user tools dropdown so it's more accessible to me and less accessible to everyone reading my userpage |
|||
// documentation at [[mw:ResourceLoader/Core modules]] and https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.util-method-addPortletLink |
|||
// First wait for mediawiki.util to load, and the page to be ready. |
|||
mw.loader.using('mediawiki.util', function() { |
|||
// General usage pattern: mw.util.addPortletLink( portletId, href, text /* Optional: , id, tooltip, accesskey, nextnode */ ); |
|||
// personal common.js |
|||
mw.util.addPortletLink( |
|||
'p-personal', |
|||
mw.util.getUrl('User:Gifted9/common.js'), |
|||
'User:Gifted9/common.js'); |
|||
// all subpages of my userpage |
|||
mw.util.addPortletLink( |
|||
'p-personal', |
|||
mw.util.getUrl('Special:PrefixIndex/User:Gifted9'), |
|||
'Special:PrefixIndex/User:Gifted9'); |
|||
/** |
/** |
||
Line 13: | Line 33: | ||
.after( $( '<a>' ).attr( 'href', url + 'history' ).text( 'hist' ) ).after( ' | ' ) |
.after( $( '<a>' ).attr( 'href', url + 'history' ).text( 'hist' ) ).after( ' | ' ) |
||
}); |
}); |
||
}); |
|||
/*** Restorer ***/ |
|||
// Easily restore an older version of a page |
|||
// Documentation at [[w:User:BrandonXLF/Restorer]] |
|||
// By [[w:User:BrandonXLF]] |
|||
$(function() { |
|||
if (mw.config.get('wgAction') != 'history') return; |
|||
window.restorerSummary = window.restorerSummary || |
|||
'Restored revision $ID by [[Special:Contributions/$USER|$USER]] ([[w:User:BrandonXLF/Restorer|Restorer]])'; |
|||
function restore(revid) { |
|||
var api = new mw.Api(); |
|||
return api.get({ |
|||
action: 'query', |
|||
revids: revid, |
|||
prop: 'revisions', |
|||
rvprop: 'user', |
|||
format: 'json', |
|||
formatversion: '2' |
|||
}).then(function(res) { |
|||
var user = res.query.pages[0].revisions[0].user; |
|||
return api.postWithEditToken({ |
|||
action: 'edit', |
|||
pageid: mw.config.get('wgArticleId'), |
|||
undo: mw.config.get('wgCurRevisionId'), |
|||
undoafter: revid, |
|||
summary: window.restorerSummary.replace(/\$ID/g, revid).replace(/\$USER/g, user) |
|||
}); |
|||
}).then( |
|||
function() { |
|||
mw.notify('Restored revision successfully.'); |
|||
location.reload(); |
|||
}, |
|||
function(_, data) { |
|||
mw.notify(api.getErrorMessage(data), {type: 'error'}); |
|||
} |
|||
); |
|||
} |
|||
function addLink(item) { |
|||
var revid = item.getAttribute('data-mw-revid'); |
|||
if (revid == mw.config.get('wgCurRevisionId')) return; |
|||
var links = item.querySelector('.comment + .mw-changeslist-links'); |
|||
if (!links) return; |
|||
var parent = document.createElement('span'), |
|||
el = document.createElement('a'); |
|||
el.addEventListener('click', function() { |
|||
el.className = 'restorer-loading'; |
|||
restore(revid).always(function() { |
|||
el.className = ''; |
|||
}); |
|||
}); |
|||
el.textContent = 'restore'; |
|||
parent.appendChild(el); |
|||
links.appendChild(parent); |
|||
} |
|||
var parents = document.querySelectorAll('li[data-mw-revid]'); |
|||
for (var i = 0; i < parents.length; i++) { |
|||
// import |
|||
addLink(parents[i]); |
|||
} |
|||
mw.loader.addStyleTag( |
|||
importArticles({ |
|||
'@keyframes restorer-loading {' + |
|||
type: 'script', |
|||
'0%, 100% {content: " ⡁"} 16% {content: " ⡈"} 33% {content: " ⠔"} 50% {content: " ⠒"} 66% {content: " ⠢"} 83% {content: " ⢁"}}' + |
|||
articles: [ |
|||
'.restorer-loading::after {white-space: pre; content: ""; animation: restorer-loading 0.5s infinite}' |
|||
'u:dev:MediaWiki:CodeLinksDropdown.js', |
|||
); |
|||
] |
|||
}); |
}); |
Latest revision as of 17:10, 25 March 2023
// javascript wiki browser: autowikibrowser but slightly uglier and in-browser, for when i'm not on my home computer
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');
// add somewhat sensitive stuff to my user tools dropdown so it's more accessible to me and less accessible to everyone reading my userpage
// documentation at [[mw:ResourceLoader/Core modules]] and https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.util-method-addPortletLink
// First wait for mediawiki.util to load, and the page to be ready.
mw.loader.using('mediawiki.util', function() {
// General usage pattern: mw.util.addPortletLink( portletId, href, text /* Optional: , id, tooltip, accesskey, nextnode */ );
// personal common.js
mw.util.addPortletLink(
'p-personal',
mw.util.getUrl('User:Gifted9/common.js'),
'User:Gifted9/common.js');
// all subpages of my userpage
mw.util.addPortletLink(
'p-personal',
mw.util.getUrl('Special:PrefixIndex/User:Gifted9'),
'Special:PrefixIndex/User:Gifted9');
/**
* adds history and delete links to Special:WhatLinksHere
* @source: https://www.mediawiki.org/wiki/Snippets/Special:WhatLinksHere_history_link
* @rev: 2
*/
$( '#mw-whatlinkshere-list li' ).each( function() {
var url = mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( $( 'a:first', this ).text() ) + '&action=';
$( '.mw-whatlinkshere-tools a:last', this )
.after( $( '<a>' ).attr( 'href', url + 'delete' ).text( 'delete' ) ).after( ' | ' )
.after( $( '<a>' ).attr( 'href', url + 'history' ).text( 'hist' ) ).after( ' | ' )
});
});
/*** Restorer ***/
// Easily restore an older version of a page
// Documentation at [[w:User:BrandonXLF/Restorer]]
// By [[w:User:BrandonXLF]]
$(function() {
if (mw.config.get('wgAction') != 'history') return;
window.restorerSummary = window.restorerSummary ||
'Restored revision $ID by [[Special:Contributions/$USER|$USER]] ([[w:User:BrandonXLF/Restorer|Restorer]])';
function restore(revid) {
var api = new mw.Api();
return api.get({
action: 'query',
revids: revid,
prop: 'revisions',
rvprop: 'user',
format: 'json',
formatversion: '2'
}).then(function(res) {
var user = res.query.pages[0].revisions[0].user;
return api.postWithEditToken({
action: 'edit',
pageid: mw.config.get('wgArticleId'),
undo: mw.config.get('wgCurRevisionId'),
undoafter: revid,
summary: window.restorerSummary.replace(/\$ID/g, revid).replace(/\$USER/g, user)
});
}).then(
function() {
mw.notify('Restored revision successfully.');
location.reload();
},
function(_, data) {
mw.notify(api.getErrorMessage(data), {type: 'error'});
}
);
}
function addLink(item) {
var revid = item.getAttribute('data-mw-revid');
if (revid == mw.config.get('wgCurRevisionId')) return;
var links = item.querySelector('.comment + .mw-changeslist-links');
if (!links) return;
var parent = document.createElement('span'),
el = document.createElement('a');
el.addEventListener('click', function() {
el.className = 'restorer-loading';
restore(revid).always(function() {
el.className = '';
});
});
el.textContent = 'restore';
parent.appendChild(el);
links.appendChild(parent);
}
var parents = document.querySelectorAll('li[data-mw-revid]');
for (var i = 0; i < parents.length; i++) {
addLink(parents[i]);
}
mw.loader.addStyleTag(
'@keyframes restorer-loading {' +
'0%, 100% {content: " ⡁"} 16% {content: " ⡈"} 33% {content: " ⠔"} 50% {content: " ⠒"} 66% {content: " ⠢"} 83% {content: " ⢁"}}' +
'.restorer-loading::after {white-space: pre; content: ""; animation: restorer-loading 0.5s infinite}'
);
});