User:Luxfx/Noarticletext.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Luxfx/Noarticletext and an accompanying .css page at User:Luxfx/Noarticletext.css. |
importStylesheet("User:Luxfx/Noarticletext.css");
var noArticleOnboard = (function(jQuery, window, mw) {
var targetPage = "User:Luxfx/Noarticletext";
function isCorrectPage() {
return (mw.config.values['wgPageName'] == targetPage);
}
function checkBacklinks() {
if (jQuery("#naBacklinks").length > 0) {
var pagename = mw.config.values['wgPageName'];
// overwrite pagename to provide sample results
pagename = "Livingstone Gold Medal";
var apiCall = jQuery.getJSON('/w/api.php'
,{
'action': 'query'
,'list': 'backlinks'
,'format': 'json'
,'bltitle': pagename
,'bllimit': 10
,'blnamespace': '0'
}
, function(data) {
if (data && data.query && data.query.backlinks && data.query.backlinks.length > 0) {
var numlinks = data.query.backlinks.length;
jQuery("#naBacklinks").html("Quick scan has found " + numlinks + " link(s)!");
} else {
jQuery("#naBacklinks").html("No links found by quick scan.");
}
}
);
}
}
function quickSearch() {
if (jQuery("#naSearch").length > 0) {
var pagename = mw.config.values['wgPageName'];
// overwrite pagename to provide sample results
pagename = "Otto Becher";
var apiCall = jQuery.getJSON('/w/api.php'
,{
'action': 'query'
,'list': 'search'
,'format': 'json'
,'srsearch': pagename
,'srlimit': 10
,'srnamespace': '0'
}
, function(data) {
if (data && data.query && data.query.searchinfo && data.query.searchinfo.totalhits > 0) {
var numhits = data.query.searchinfo.totalhits;
jQuery("#naSearch").html("There are at least " + numhits + " articles mentioning this topic.");
} else {
jQuery("#naSearch").html("No articles found by quick scan mention this topic.");
}
}
);
}
}
function showScriptArea() {
jQuery("#naNoscript").hide();
jQuery("#naWithscript").show();
}
return {
init: function() {
if (!isCorrectPage()) return false;
showScriptArea();
checkBacklinks();
quickSearch();
}
};
}(jQuery, window, mw));
addOnloadHook(noArticleOnboard.init);