User:Novem Linguae/Scripts/VoteCounter.js
Appearance
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:Novem Linguae/Scripts/VoteCounter. |
// <nowiki>
/*
-
*/
mw.loader.using('mediawiki.storage').then(function () {
mw.storage.session.set( 'client-error-opt-out', '1' );
});
$(function() {
function getWikicode(title) {
// https://www.mediawiki.org/wiki/API:Get_the_contents_of_a_page#Method_1:_Use_the_Revisions_API
// https://en.wikipedia.org/w/api.php?action=parse&page=Pet_door&prop=wikitext&formatversion=2
var wikicode = '';
title = encodeURIComponent(title);
$.ajax({
url: 'https://en.wikipedia.org/w/api.php?action=parse&page='+title+'&prop=wikitext&formatversion=2&format=json',
success: function (result) {
wikicode = result['parse']['wikitext'];
},
dataType: "json",
async: false
});
return wikicode;
}
/** returns the pagename, including the namespace name, but with spaces replaced by underscores */
function getArticleName() {
return mw.config.get('wgPageName');
}
// don't run when not viewing articles
let action = mw.config.get('wgAction');
if ( action != 'view' ) return;
// only run in talk namespaces (all of them) or Wikipedia namespace
let namespace = mw.config.get('wgNamespaceNumber');
if ( ! [4, 1, 3, 5, 7, 9, 11, 13, 15, 101, 119, 711, 829, 2301, 2303].includes(namespace) ) {
return;
}
// get wikitext
let title = getArticleName();
let wikicode = getWikicode(title);
console.log(wikicode);
// count the following
// - keep
// - delete
// - support
// - oppose
// caveats:
// - don't count strikethroughs
// - don't get thrown off by weak/strong
// display totals on page using JQuery
// will need to eventually do it by section instead of by page. these pages have it by section:
// - RFC
// - TFD
// - CFD
// - RFD
// - RFC
// these pages have it by page:
// - RFA
// - AFD
// - MFD
// need to count the initial vote as a keep/delete. check type of page for this
});
// </nowiki>