User:Pyrospirit/metadata.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
/*********************************** Metadata assessment script ************************************/ /*********************** GLOBAL VARIABLES ************************/ if (typeof TitleColor === 'object') var MetadataAssessmentColor = TitleColor; if (typeof MetadataAssessmentColor === 'undefined') var MetadataAssessmentColor = {}; if (typeof MetadataAssessmentColor.link === 'undefined') MetadataAssessmentColor.link = (skin == 'modern') ? '#003366' : '#002BB8'; if (typeof MetadataAssessmentColor.FA === 'undefined') MetadataAssessmentColor.FA = '#0066CC'; if (typeof MetadataAssessmentColor.A === 'undefined') MetadataAssessmentColor.A = '#007BFF'; if (typeof MetadataAssessmentColor.GA === 'undefined') MetadataAssessmentColor.GA = '#007700'; if (typeof MetadataAssessmentColor.B === 'undefined') MetadataAssessmentColor.B = '#999933'; if (typeof MetadataAssessmentColor.C === 'undefined') MetadataAssessmentColor.C = '#AA801A'; if (typeof MetadataAssessmentColor.start === 'undefined') MetadataAssessmentColor.start = '#BB6600'; if (typeof MetadataAssessmentColor.stub === 'undefined') MetadataAssessmentColor.stub = '#990011'; if (typeof MetadataAssessmentColor.list === 'undefined') MetadataAssessmentColor.list = (skin == 'modern') ? '#AA88FF' : '#8833CC'; if (typeof MetadataAssessmentColor.dab === 'undefined') MetadataAssessmentColor.dab = (skin == 'modern') ? '#00FA9A' : '#33CC77'; if (typeof MetadataAssessmentColor.redir === 'undefined') MetadataAssessmentColor.redir = (skin == 'modern') ? '#FFFFFF' : '#000000'; if (typeof MetadataAssessmentColor.none === 'undefined') MetadataAssessmentColor.none = (skin == 'modern') ? '#FFFFFF' : '#000000'; /*********************** FUNCTIONS ************************/ // Global wrapper for whole script. Prevents variable and function names from // spilling over into other scripts. function MetadataAssessmentScript () { var color = MetadataAssessmentColor; var linkLead = '<a style="color:' + color.link + ';" href="/wiki/Wikipedia:Version_1.0_Editorial_Team/Assessment">'; function update (color, slogan, info) { document.getElementsByTagName('h1')[0].style.cssText = 'color: ' + color + ';'; document.getElementById('siteSub').innerHTML = '<i>' + slogan + '</i> ' + 'from Wikipedia, the free encyclopedia' + info; } function talk_assess (text) { var info = ''; if ( text.match(/\{\{ganominee/i) ) { info = '. <i>Currently a <a href="' + wgServer + '/w/index.php?title=Wikipedia:Good_article_candidates" style="color:' + color.link + ';">Good Article candidate</a></i>.'; } else if ( text.match(/\{\{fac\}/i) ) { info = '. <i>Currently a <a href="' + wgServer + '/w/index.php?title=Wikipedia:Featured_article_candidates/' + encodeURIComponent(wgPageName) + '&redirect=no" style="color:' + color.link + ';">Featured Article candidate</a></i>.'; } else if ( text.match(/\{\{FormerFA2?/i) || text.match(/currentstatus *= *FFA[^A-Z]/i) ) { info = '. <i>A <a href="' + wgServer + '/w/index.php?title=Category:Wikipedia former featured articles" style="color:' + color.link + ';">former</a> Featured Article</i>.'; } else if ( text.match(/\{\{flc\}/i) ) { info = '. <i>Currently a <a href="' + wgServer + '/w/index.php?title=Wikipedia:Featured_list_candidates/' + encodeURIComponent(wgPageName) + '&redirect=no" style="color:' + color.link + ';">Featured List candidate</a></i>.'; } if ( text.match(/class *= *ga/i) || text.match(/currentstatus *= *(ffa\/)?ga/i) ) { update(color.GA, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Good Articles">Good Article</a>', info); } else if ( text.match(/class *= *a/i) ) { update(color.A, 'An ' + linkLead + 'A-class</a> article', info); } else if ( text.match(/class *= *b/i) ) { update(color.B, 'A ' + linkLead + 'B-class</a> article', info); } else if ( text.match(/class *= *c/i) ) { update(color.C, 'A ' + linkLead + 'C-class</a> article', info); } else if ( text.match(/class *= *start/i) ) { update(color.start, 'A ' + linkLead + 'Start-class</a> article', info); } else if ( text.match(/class *= *stub/i) ) { update(color.stub, 'A ' + linkLead + 'Stub-class</a> article', info); } else if ( text.match(/class *= *list/i) ) { update(color.list, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Lists">List-class</a> article', info); } else if ( text.match(/class *= *(dab|disambig)/i) ) { update(color.dab, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Disambiguation">Disambiguation page</a>', info); } else { update(color.none, 'An ' + linkLead + 'unassessed</a> article', info); } } function load (url) { var request = sajax_init_object(); if (request) { request.onreadystatechange = function () { if (request.readyState == 4) { if (request.status == 200) { talk_assess(request.responseText); } } }; request.open('GET', url, true); request.send(null); } } function begin () { var url = false if ( document.getElementById('featured-star') ) { if ( document.getElementById('featured-star').innerHTML.match(/\blist\b/i) ) { update(color.FA, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Featured_lists">Featured List</a>', ''); } else { update(color.FA, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Featured_articles">Featured Article</a>', ''); } } else if ( document.getElementById('disambig') ) { update(color.dab, 'A <a style="color:' + color.link + ';" href="/wiki/Wikipedia:Disambiguation">Disambiguation page</a>', ''); } else if ( document.getElementById('contentSub').innerHTML == 'Redirect page' ) { update(color.redir, 'A <a style="color:' + color.link + ';" href="/wiki/Help:Redirect">Redirect page</a>', ''); } else if ( document.getElementById('ca-talk').className == 'new' ) { update(color.none, 'An ' + linkLead + 'unassessed</a> article', ''); } else { url = wgServer + wgScriptPath + '/index.php?title=Talk:' + encodeURIComponent(wgTitle) + '&action=raw§ion=0'; } return url } function main () { color = MetadataAssessmentColor; // ensure colors update var url = begin(); if (url) load(url) } if ( wgNamespaceNumber == 0 && (wgAction == 'view' || wgAction == 'purge') && wgPageName != 'Main_Page' ) { addOnloadHook(main); } } // end global wrapper /*********************** EXECUTE SCRIPT ************************/ MetadataAssessmentScript();