User:Alex 21/script-tvepisoderatings.js

$(function($) {	setTimeout(function { $.when( mw.loader.using( ['mediawiki.util']), $.ready ).then(function {			var portletlink = mw.util.addPortletLink('p-tv', '#', 'Television episode ratings');			$(portletlink).click( function(e) { e.preventDefault; var loc = window.location.href; var i; var _j = 1; if (loc.indexOf('action=edit') < 0 && loc.indexOf('action=submit') < 0) { // Find all sortable tables var tables = document.getElementsByClassName('sortable'); var alltables = ""; var checkedcols = false; for (i = 0; i < tables.length; i++) { // Begin template alltables += "\n\n"; alltables = alltables.replace(/\|(.*)\= (.*)tb[a|d](.*)\n/g,''); }					// Copy, alert that references need to be copied as well copyContent(alltables); alert('Tables copied. You will need to paste them before copying the referenes. Now click the edit link for the Ratings section.'); } else { // Copy all references in section containing ratings tables var allrefs = ''; var wpTextbox1 = document.getElementById('wpTextbox1').value.split("\n"); for (i = 0; i < wpTextbox1.length; i++) { var res1 = /(.*)<\/ref>/.exec(wpTextbox1[i]); if (res1 && allrefs.indexOf(res1[0]) < 0) allrefs += res1[0]+"\n"; var res2 = /]*)\/>/.exec(wpTextbox1[i]); if (res2 && allrefs.indexOf(res2[0]) < 0) allrefs += res2[0]+"\n"; }					// Copy, done copyContent(allrefs); alert('References copied.'); }				// HLCR: HTML content, lower case, references removed function hlcr(x) { return x.innerHTML.toLowerCase.replace(//g,''); } });		});	},800); });