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 += "{{Television episode ratings\n";
for (var j = 1; j < tables[i].rows.length; j++, _j++) {
var link; var cells = tables[i].rows[j].cells;
// Header cell
if (cells[0].tagName == 'TH') { _j--; continue; }
else if (!checkedcols) {
// Add parameters for demographics that aren't used
if (cells[3] === undefined) alltables += "| hide_rs = y\n";
if (cells[4] === undefined) alltables += "| hide_viewers = y\n";
if (cells[5] === undefined) alltables += "| hide_dvr = y\n";
if (cells[6] === undefined) alltables += "| hide_dvrv = y\n";
if (cells[7] === undefined) alltables += "| hide_total = y\n";
if (cells[8] === undefined) { alltables += "| hide_totalv = y\n"; alltables += "\n"; }
checkedcols = true;
}
// Title cell including link
if (cells[1].children.length > 0) {
link = cells[1].children[0];
var elem = document.createElement('textarea');
elem.innerHTML = link.innerHTML;
title = (link.title?link.title:link.href.substr(link.href.indexOf("#")));
link = "[["+title+(title!=link.innerHTML?"|"+elem.value:"")+"]]";
} else {
link = cells[1].innerHTML.substr(1, cells[1].innerHTML.length-2);
}
// Date cell
var date = (cells[2].children.length>1?cells[2].children[1]:cells[2]).innerHTML;
date = date.replace(/ /g,' ').replace(/<span(.*)\/span\>/g,'');
// Include all demographics if included, minus references
alltables += "| title"+ _j +" = "+link+"\n";
alltables += "| date"+ _j +" = "+date+"\n";
if (cells[3] !== undefined) alltables += "| rs"+ _j +" = "+hlcr(cells[3])+"\n";
if (cells[4] !== undefined) alltables += "| viewers"+ _j +" = "+hlcr(cells[4])+"\n";
if (cells[5] !== undefined) alltables += "| dvr"+ _j +" = "+hlcr(cells[5])+"\n";
if (cells[6] !== undefined) alltables += "| dvrv"+ _j +" = "+hlcr(cells[6])+"\n";
if (cells[7] !== undefined) alltables += "| total"+ _j +" = "+hlcr(cells[7])+"\n";
if (cells[8] !== undefined) alltables += "| totalv"+ _j +" = "+hlcr(cells[8])+"\n";
if (j != tables[i].rows.length-1) alltables += "\n";
}
// All completed, after removal of any occurrences of lowercase tba/tbd
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(.*)>(.*)<\/ref>/.exec(wpTextbox1[i]);
if (res1 && allrefs.indexOf(res1[0]) < 0) allrefs += res1[0]+"\n";
var res2 = /<ref([^>]*)\/>/.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(/<sup(.*)\/sup\>/g,''); }
});
});
},800);
});
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.