Content deleted Content added
try to fix FA code |
m Maintenance: Fixing deprecated call to addPortletLink (mw:ResourceLoader/Migration_guide_(users)#addPortletLink) |
||
(20 intermediate revisions by 2 users not shown) | |||
Line 1:
//<pre>
// Translate interwiki codes such as "simple" and "ar"
//
// To use this script, add "importScript('User:Proteins/translateinterwikicodes.js');" to your monobook.js subpage
// under your user page, as you can see at User:Proteins/monobook.js
var interwiki_English_names = {
Line 369 ⟶ 372:
var alert_string;
var num_lines_printed = 0;
var describe_results = false;
var on_main_page = false;
var translate_all_extiw_hyperlinks = true;
var parent_node;
Line 383 ⟶ 389:
var English_translation;
var num_interwiki_links_translated = 0;
var interwiki_link_string = "interwiki link";
// Check whether we're on the Main Page
Line 409 ⟶ 417:
}
}
interwiki_link_string = "interwiki link";
alert_string += "This page has " + num_hyperlinks + " potential interwiki links.\n\n";▼
if (num_hyperlinks != 1) { interwiki_link_string += "s"; };
▲ alert_string += "This page has " + num_hyperlinks + " potential
num_lines_printed += 2;
// window.alert(alert_string); alert_string = "";
Line 418 ⟶ 428:
if (num_lines_printed>45) { // in cases of many error messages
if (describe_results) { window.alert(alert_string); }
alert_string = "";
num_lines_printed = 0;
Line 435 ⟶ 445:
}
if (!parent_node.className) {
// alert_string += "No className for parent node in hyperlink " + hyperlink_index + "\n";
num_lines_printed++;
continue;
Line 441 ⟶ 451:
language_code = parent_node.className.replace(/interwiki-/, "");
language_code =
English_translation = interwiki_English_names[language_code];
Line 452 ⟶ 462:
if ((hyperlink_counter%40 == 1) && (hyperlink_counter > 1)) {
if (describe_results) { window.alert(alert_string); }
alert_string = "Continued...\n\n";
}
Line 458 ⟶ 468:
temp_hyperlink.innerHTML = English_translation;
} // closes loop over interwiki links
window.alert(alert_string);▼
interwiki_link_string = "interwiki link";
// Translate other interwiki links, but only on the Main Page ▼
if (num_interwiki_links_translated != 1) { interwiki_link_string += "s"; };
alert_string += "\nTranslated " + num_interwiki_links_translated + " " + interwiki_link_string + " into English.";
if (describe_results) { window.alert(alert_string); }
alert_string = "";
translate_all_extiw_hyperlinks = true;
if ((translate_all_extiw_hyperlinks) || (on_main_page)) {
num_hyperlinks = 0;
hyperlinks = document.getElementsByTagName("A"); // earlier code was restricted to mp-lang on Main Page
alert_string += "
} else {
▲ if (!hyperlinks) {
▲ num_hyperlinks = hyperlinks.length;
}
// window.alert(alert_string); alert_string = "";▼
hyperlink_counter = 0;
Line 484 ⟶ 493:
if (temp_hyperlink.className != "extiw") { continue; }
if (temp_hyperlink.title == "m:List of Wikipedias") { continue; }
language_code = temp_hyperlink.title.replace(/:/, "");
Line 494 ⟶ 504:
hyperlink_counter++;
if ((hyperlink_counter%40 == 1) && (hyperlink_counter > 1)) {
if (describe_results) { window.alert(alert_string); }
alert_string = "Continued...\n\n";
}
alert_string += "Interwiki link " + hyperlink_counter + " : " + language_code + " => " + English_translation + "\n";
temp_hyperlink.innerHTML = English_translation;
} // closes loop over interwiki links
▲ window.alert(alert_string);
interwiki_link_string = "interwiki link";
if (hyperlink_counter != 1) { interwiki_link_string += "s"; };
alert_string += "\nTranslated " + hyperlink_counter + " " + interwiki_link_string + " at the bottom of the Main Page into English.";
} // closes check for being on the Main Page
// Minimal acknowledgment message
if (!describe_results) {
interwiki_link_string = "interwiki link";
if (num_interwiki_links_translated != 1) { interwiki_link_string += "s"; };
alert_string = "\nTranslated " + num_interwiki_links_translated + " " + interwiki_link_string + " into English.";
▲ }
} // closes function translateInterwikiCodes()
mw.util.addPortletLink('p-
});
|