User:PerfektesChaos/js/idResolver/d.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:PerfektesChaos/js/idResolver/d. |
/// User:PerfektesChaos/js/idResolver/d.js
/// 2018-09-04 PerfektesChaos@de.wikipedia
// Run ID resolving alternatives on HTML page
// ResourceLoader: compatible;
// dependencies: "user", "mediawiki.util",
// "oojs", "oojs-ui-core", "oojs-ui-widgets"
/// Documentation: [[w:en:User:PerfektesChaos/js/idResolver]]
/// Fingerprint: #0#0#
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/* global window: false */
/* jshint forin: false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var VERSION = -1.7,
IDA = "idResolver",
IDEA = { load: true,
sub: "/core",
type: IDA };
if ( typeof mw.libs[ IDA ] !== "object"
|| ! mw.libs[ IDA ] ) {
mw.libs[ IDA ] = { };
}
IDA = mw.libs[ IDA ];
if ( typeof IDA.vsn === "string" ) {
IDA.vsn = "*" + VERSION + " " + IDA.vsn;
} else {
IDA.vsn = "" + VERSION;
}
IDA.type = IDEA.type;
IDA.signature = "ext.gadget." + IDA.type;
IDA.support = "User:PerfektesChaos/js/" + IDA.type;
IDA.doc = "[[w:en:" + IDA.support + "]]";
function facilitate( activate ) {
// Callback from core completion
// Precondition:
// activate -- function, to run core business
// Uses:
// > IDA
// > IDEA.cfg
// 2016-05-01 PerfektesChaos@de.wikipedia
activate( IDA, IDEA.cfg );
} // facilitate()
function faculty( after ) {
// Run Special:Gadgets form
// Precondition:
// after -- form initialization function
// Uses:
// > IDEA.prego
// > IDEA.cfg
// 2016-05-01 PerfektesChaos@de.wikipedia
after( IDEA.prego, IDEA.cfg );
} // faculty()
function features( assign ) {
// Assign set of user options
// Precondition:
// assign -- object with assignments
// Uses:
// > IDEA.pars
// < IDEA.rooms
// < IDEA.cfg
// < IDEA.opt
// 2016-09-01 PerfektesChaos@de.wikipedia
var part, s;
for ( s in assign ) {
if ( s === "rooms" ) {
if ( typeof assign.rooms === "object" ) {
part = assign.rooms;
if ( part &&
typeof part.length === "number"
&& part.length ) {
IDEA.rooms = part;
}
}
} else if ( s === "types" ) {
if ( typeof assign.types === "object"
&& assign.types ) {
IDEA.cfg.types = assign.types;
}
} else if ( typeof IDEA.pars[ s ] === "undefined" ) {
IDEA.cfg[ s ] = assign[ s ];
} else if ( typeof assign[ s ] === IDEA.pars[ s ] ) {
IDEA.opt[ s ] = assign[ s ];
}
} // for s in assign
} // features()
function featuring( auxilary ) {
// Appreciate user options
// Precondition:
// auxilary -- preferencesGadgetOptions library object
// Postcondition:
// Returns true if page is unconditionally subject for equipment
// Uses:
// > IDA.opt
// > IDA.type
// >< IDEA.opt
// >< IDEA.rooms
// < IDEA.cfg
// < IDEA.lazy
// < IDEA.lock
// features()
// mw.hook()
// mw.libs.preferencesGadgetOptions.fetch()
// 2017-02-06 PerfektesChaos@de.wikipedia
var i, s, v, vals;
IDEA.cfg = { make: 0 };
IDEA.opt = { spaces: false };
IDEA.pars = { launch: "boolean",
layer: "boolean",
lazy: "boolean",
light: "boolean",
linking: "boolean",
lock: "boolean",
make: "number",
seen: "string",
spaces: "string",
debug: "boolean" };
for ( s in IDEA.pars ) {
IDEA.opt[ s ] = false;
} // for s in pars
if ( typeof IDA.opt === "object"
&& IDA.opt ) {
features( IDA.opt );
}
mw.hook( IDA.type + ".before" ).add( features );
if ( typeof auxilary === "object"
&& auxilary ) {
if ( typeof auxilary.fetch === "function" ) {
vals = auxilary.fetch( IDA.type );
if ( vals && typeof vals === "object" ) {
for ( s in IDEA.pars ) {
if ( typeof vals[ s ] === IDEA.pars[ s ] ) {
IDEA.opt[ s ] = vals[ s ];
}
} // for s in pars
if ( IDEA.opt.spaces ) {
if ( typeof IDEA.rooms !== "object" ) {
IDEA.rooms = [ ];
}
vals = IDEA.opt.spaces.split( " " );
for ( i = 0; i < vals.length; i++ ) {
v = parseInt( vals[ i ], 10 );
if ( ! isNaN( v ) ) {
IDEA.rooms.push( Math.floor( v ) );
}
}
}
}
}
}
IDEA.lazy = IDEA.opt.lazy;
IDEA.lock = IDEA.opt.lock;
IDEA.cfg.layer = IDEA.opt.layer;
IDEA.cfg.light = IDEA.opt.light;
IDEA.cfg.linking = IDEA.opt.linking;
if ( typeof IDEA.opt.make === "number"
&& IDEA.opt.make >= 0 ) {
IDEA.cfg.make = Math.floor( IDEA.opt.make );
}
return IDEA.opt.launch;
} // featuring()
function feed( assigned, access, after, age ) {
// Run subscript
// Precondition:
// assigned -- signature
// access -- script
// after -- callback
// age -- maxage, or false
// Uses:
// > VERSION
// > IDEA.opt.debug
// >< IDEA.level
// mw.loader.getState()
// mw.loader.state()
// mw.loader.load()
// mw.hook()
// 2018-09-04 PerfektesChaos@de.wikipedia
var maxage, rls;
if ( ! mw.loader.getState( assigned ) ) {
rls = { };
rls[ assigned ] = "loading";
mw.loader.state( rls );
if ( typeof IDEA.level !== "boolean" ) {
IDEA.level = ( VERSION > 0 );
if ( IDEA.level &&
typeof IDEA.opt === "object"
&& IDEA.opt &&
typeof IDEA.opt.debug === "boolean"
&& IDEA.opt.debug ) {
IDEA.level = false;
}
}
maxage = ( age ? age
: ( IDEA.level ? 86400 : 1000 ) );
mw.loader.load( "https://en.wikipedia.org"
+ "/w/index.php?title="
+ "User:PerfektesChaos/js/"
+ access + "/"
+ ( IDEA.level ? "r" : "d" ) + ".js"
+ "&bcache=1&maxage=" + maxage
+ "&action=raw"
+ "&ctype=text/javascript",
"text/javascript" );
}
if ( after ) {
mw.hook( access + ".ready" ).add( after );
}
} // feed()
function fetch( activity ) {
// Run core
// Precondition:
// activity -- event
// Uses:
// > IDA.signature
// > IDEA.sub
// > IDA.type
// >< IDEA.load
// feed()
// (facilitate)
// 2016-11-11 PerfektesChaos@de.wikipedia
if ( typeof activity === "object" && activity ) {
if ( typeof activity.preventDefault === "function" ) {
activity.preventDefault();
}
if ( typeof activity.stopPropagation === "function" ) {
activity.stopPropagation();
}
}
if ( IDEA.load ) {
IDEA.load = false;
feed( IDA.signature + IDEA.sub,
IDA.type + IDEA.sub,
facilitate );
}
} // fetch()
function figure( auxilary ) {
// Prepare Special:Gadgets
// Precondition:
// auxilary -- preferencesGadgetOptions library object
// Uses:
// > IDA.type
// < IDEA.prego
// featuring()
// (faculty)
// 2016-05-01 PerfektesChaos@de.wikipedia
IDEA.prego = auxilary;
featuring( auxilary );
mw.hook( IDA.type + "/prego.ready" ).add( faculty );
} // figure()
function fill() {
// Provide trigger for manual start of analysis
// Precondition:
// document ready
// "mediawiki.util"
// Uses:
// > IDA.type
// > IDA.vsn
// mw.util.addPortletLink()
// (fetch)
// 2016-05-01 PerfektesChaos@de.wikipedia
var portlet = mw.util.addPortletLink( "p-tb",
"#",
IDA.type,
"t-" + IDA.type ),
$portlet = $( portlet );
$portlet.click( fetch );
$portlet.attr( { title: IDA.type + " " + IDA.vsn } );
} // fill()
function filter( auxilary ) {
// Check user options for meaningful usage
// Precondition:
// auxilary -- preferencesGadgetOptions library object
// Uses:
// > IDEA.nsn
// > IDEA.rooms
// > IDEA.lazy
// > IDEA.lock
// mw.config.get()
// featuring()
// mw.loader.using()
// fetch()
// mw.hook()
// (fill)
// 2016-10-20 PerfektesChaos@de.wikipedia
var env = mw.config.get( [ "wgTitle",
"wgUserName",
"wgWikibaseItemId" ] ),
launch = featuring( auxilary );
if ( ! launch ) {
switch ( IDEA.nsn ) {
case 0:
launch = true;
break;
case 2:
launch = ( ! env.wgTitle.indexOf( env.wgUserName
+ "/" ) );
break;
case 4:
if ( typeof env.wgWikibaseItemId === "string" &&
env.wgWikibaseItemId.toUpperCase() === "Q3938" ) {
launch = true;
}
break;
} // switch envNamespaceNumber
}
if ( ! launch &&
IDEA.rooms &&
$.inArray( IDEA.nsn, IDEA.rooms ) >= 0 ) {
launch = true;
}
if ( launch ) {
if ( IDEA.lazy ) {
mw.loader.using( [ "mediawiki.util" ],
function () {
$( fill );
} );
} else if ( ! IDEA.lock ) {
fetch();
} else {
mw.hook( IDA.type + ".fire" ).fire( fetch );
}
}
} // filter()
function fire() {
// Intialize application, check for meaningful usage
// Uses:
// > IDA.signature
// > IDA.type
// < IDEA.nsn
// mw.loader.getState()
// mw.loader.state()
// mw.config.get()
// feed()
// (figure)
// (filter)
// 2018-08-24 PerfektesChaos@de.wikipedia
var callback, env, rls, scope;
if ( mw.loader.getState( IDA.signature ) !== "ready" ) {
rls = { };
rls[ IDA.signature ] = "ready";
mw.loader.state( rls );
env = mw.config.get( [ "wgAction",
"wgCanonicalSpecialPageName",
"wgNamespaceNumber",
"wgPageContentModel" ] );
scope = "|view|submit|edit|";
if ( env.wgNamespaceNumber < 0 ) {
if ( env.wgCanonicalSpecialPageName === "Blankpage" ) {
// "Gadgets"
feed( IDA.signature + "/prego",
IDA.type + "/prego",
false );
callback = figure;
}
} else if ( scope.indexOf( env.wgAction ) > 0 &&
env.wgPageContentModel === "wikitext" ) {
IDEA.nsn = env.wgNamespaceNumber;
callback = filter;
}
if ( callback ) {
feed( "ext.gadget.preferencesGadgetOptions",
"preferencesGadgetOptions",
callback,
86410 );
}
}
} // fire()
fire();
}( window.mediaWiki, window.jQuery ) );
/// EOF </nowiki> idResolver/d.js