User:JPxG/wigout.js

// This is a very stupid script.

// Add it, and you'll get a button at the top of CCI casepages that lets you add links to Earwig's Copyright Checker next to each diff.

// - JPxG, 2021 08 31

$( function() {

if( ((window.location.href.indexOf( "Contributor copyright investigations" ) >= 0 ) || (window.location.href.indexOf( "Contributor_copyright_investigations" ) >= 0 )) && (window.location.href.indexOf( "&action=edit" ) == -1)) { wigLink = "https://copyvios.toolforge.org/?lang=en&project=wikipedia&action=search&use_engine=1&use_links=1&oldid="

wigLinkTitle = "https://copyvios.toolforge.org/?lang=en&project=wikipedia&action=search&use_engine=1&use_links=1&title="

z = "​"

// NOT AN EMPTY STRING! THIS IS A ZERO-WIDTH SPACE.

as = document.querySelectorAll('a')

acnt = 0

// Count the number of "a"s (initially zero)

bcnt = document.querySelectorAll('a').length;

$('.firstHeading').append('  Toggle: ');

// Add the button.

//$('.firstHeading').append(' ');

// Add the button.

var diffsexpanded = 0;

// Set toggle variable.

$('#earwigs').click(function(e) {

// Listener for "what to do if the button is clicked"

if(diffsexpanded == 0){

diffsexpanded = 1

//$( 'a' ).hide()

// Hide the diffs.

acnt = 0

x = document.getElementsByClassName('crbutton')[0]

x.innerHTML = "Adding links (please be patient, this may take several minutes)"

for(var asdf in as){

if(as[asdf].href.indexOf("Special:Diff") >= 0){

acnt++

x.innerHTML = "diffs: "+acnt

// Actually count the diffs.

let node = as[asdf];

let newLink = document.createElement("a");

// https://en.wikipedia.org/w/index.php?diff=17840192

// 0123456789012345678901234567890123456789012

// 0 10 20 30 40

// Yeah, so you'd think it started at 42, but it's 43.

newLink.href = wigLink + as[asdf].href.substring(43);

newLink.innerText = "©";

node.parentNode.insertBefore(newLink, node.nextSibling);

// marshall q. polaris is cooler than me

//console.log(as[asdf].innerHTML)

console.log(asdf)

console.log(typeof asdf)

//console.log(as[asdf].href)

//console.log("-----")

} // For every element that's a diff link.

} // For every element in the array.

// Count diffs and Strike out the text on the button.

} // If toggle is 0, hide them.

if(diffsexpanded == 1){

x = document.getElementsByClassName('crbutton')[0]

$('.firstHeading').append(" You already clicked it, buddy!")

// Unstrike the text on the button.

} // If toggle is 1, show them.

}); // End of button listener.

} // End of function.

} ); // End of the line. That's all folks!