User:JJPMaster/raddewikify.js
Appearance
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this user script can be added at User:JJPMaster/raddewikify. |
if (mw.config.get("wgArticleId") > 0)
var dewikifyLink = mw.util.addPortletLink('luna-actions', '#', 'Dewikify', 'luna-dewiki', 'Remove all links from this page');
$(dewikifyLink).click(() => {
dewikify();
});
async function getNewContent() {
var doIt = confirm("Are you sure you want to remove all of the links on this page?");
var pageContent;
if (doIt) {
var params = {
action: 'parse',
page: mw.config.get('wgPageName'),
prop: 'wikitext',
format: 'json'
};
var dewikifiedContent;
var api = new mw.Api();
const data = await api.get(params);
dewikifiedContent = data.parse.wikitext["*"].replace(/\[\[([^|\]]+)(?:\|[^|\]]+)?\]\]/gm, "$1");
return dewikifiedContent;
}
}
async function dewikify() {
var params = {
action: 'edit',
title: mw.config.get('wgPageName'),
text: await getNewContent(),
summary: 'Dewikifying page using [[User:JJPMaster/raddewikify.js|script]]',
format: 'json'
};
var api = new mw.Api();
const data = await api.postWithToken("csrf", params);
console.log(data);
alert("Done!");
}