User:PerfektesChaos/js/pageLinkHelper/d.js: Difference between revisions

Content deleted Content added
-1.91
-1.92
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
/// 2015-01-03 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible; dependencies: user, mediawiki.util
// ResourceLoader: compatible;
/// 2014-12-30 PerfektesChaos@de.wikipedia
// dependencies: user, user.options, mediawiki.user, mediawiki.util
/// Fingerprint: #0#0#
/// Fingerprint: #0#0#
/// [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
// Documentation: [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
/// <nowiki>
/*jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
Line 12 ⟶ 13:
( function ( mw, $ ) {
"use strict";
var Version = -1.9192,
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Shop = "w:en:User:PerfektesChaos/js/",
OPTS = { },
Config, Env, PLH;
 
Line 58 ⟶ 60:
"vmf" : "de" }
}; // 2014-12-22 PerfektesChaos@de.wikipedia
 
 
 
OPTS.face = function () {
// Initialize environment and application object, if user defined
// Precondition:
// module 'user' loaded
// Postcondition:
//
// Uses:
// > mw.libs
// > Sign
// > Version
// > Shop
// >< PLH
// 2014-12-22 PerfektesChaos@de.wikipedia
if ( typeof mw.libs[ Sign ] === "object" &&
mw.libs[ Sign ] &&
! PLH ) {
PLH = mw.libs[ Sign ];
PLH.vsn = Version;
PLH.doc = "[[" + Shop + Sign + "]]";
}
}; // OPTS.face()
 
 
 
OPTS.facet = function ( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > PLH
// OPTS.face()
// 2014-12-19 PerfektesChaos@de.wikipedia
var r; // = undefined
OPTS.face();
if ( PLH && typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
}
return r;
}; // OPTS.facet()
 
 
Line 90 ⟶ 137:
 
 
function $float( $apply, anchor ) {
// Insert/exchange upper right corner element
// Precondition:
// $apply -- jQuery element to insert
// false to check availability
// anchor -- string, with user defined selector, or undefined
// Postcondition:
// Returns true, if insertion possible
Line 100 ⟶ 148:
// > Sign
// >< Env
// 20142015-1201-1903 PerfektesChaos@de.wikipedia
var r, // = undefined
sequence, suitable, $anchor, $clear;
Line 107 ⟶ 155:
Env.$corner.attr( { "class": Sign,
"id": Sign + "Corner" } );
if ( ! Env.skinanchor ) {
Env.skin$anchor = mw.config.get$( "skin"anchor );
if ( $anchor.length > 1 ) {
$anchor = $anchor.eq( 0 );
}
} else {
if ( ! Env.skin ) {
Env.skin = mw.config.get( "skin" );
}
switch ( Env.skin ) {
case "cologneblue" :
suitable = "firstHeading";
sequence = "after";
break;
case "modern" :
suitable = "contentSub";
sequence = "before";
break;
case "monobook" :
case "vector" :
suitable = "bodyContent";
sequence = "prepend";
break;
} // switch Env.skin
$anchor = $( "#" + suitable );
}
switch ( Env.skin ) {
case "cologneblue" :
suitable = "firstHeading";
sequence = "after";
break;
case "modern" :
suitable = "contentSub";
sequence = "before";
break;
case "monobook" :
case "vector" :
suitable = "bodyContent";
sequence = "prepend";
break;
} // switch Env.skin
$anchor = $( "#" + suitable );
if ( ! $anchor.length ) {
$anchor = $( "#firstHeading" );
Line 140 ⟶ 195:
}
if ( Env.$corner ) {
Env.$corner.emptyif ( $apply ); {
Env.$corner.prependempty( $apply );
Env.$corner.prepend( $apply );
}
r = true;
}
return r;
} // $float()
 
 
 
function face() {
// Initialize environment and application object, if user defined
// Precondition:
// module 'user' loaded
// Postcondition:
//
// Uses:
// > mw.libs
// > Sign
// > Version
// > Shop
// >< PLH
// 2014-12-22 PerfektesChaos@de.wikipedia
if ( typeof mw.libs[ Sign ] === "object" &&
mw.libs[ Sign ] &&
! PLH ) {
PLH = mw.libs[ Sign ];
PLH.vsn = Version;
PLH.doc = "[[" + Shop + Sign + "]]";
}
} // face()
 
 
 
function facet( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > PLH
// face()
// 2014-12-19 PerfektesChaos@de.wikipedia
var r; // = undefined
face();
if ( PLH && typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
}
return r;
} // facet()
 
 
Line 250 ⟶ 262:
// > Config
// >< Env
// OPTS.face()
// facility()
// mw.config.get()
Line 260 ⟶ 272:
r = access;
}
OPTS.face();
if ( PLH &&
typeof PLH.config === "object" &&
Line 321 ⟶ 333:
// Uses:
// >< Env
// OPTS.facet()
// mw.config.get()
// fair()
Line 327 ⟶ 339:
// (apply.fun)
// 2014-12-19 PerfektesChaos@de.wikipedia
var opt = OPTS.facet( apply.signature ),
seed = null,
slot = "p-cactions",
Line 419 ⟶ 431:
return r;
} // favorite()
 
 
 
function feed( about, alter, assign ) {
// Execute URL replacement after some delay
// Precondition:
// about -- object, with reason
// alter -- string, with title
// assign -- string, with new URL
// Uses:
// history.___replaceState()
// 2015-01-03 PerfektesChaos@de.wikipedia
window.history.___replaceState( about, alter, assign );
} // feed()
 
 
Line 518 ⟶ 544:
// > document
// >< Env
// mwOPTS.config.getfacet()
// $float()
// $factory()
// fiat()
// mw.config.get()
// mw.util.wikiUrlencode()
// setTimeout()
// history.___replaceState()
// mw.util.wikiUrlencode()
// freezer()
// 2014-12-29 PerfektesChaos@de.wikipedia (feed)
// 2015-01-03 PerfektesChaos@de.wikipedia
var sign = Sign + "Difflink",
var $divlink = $( "#" + sign )false,
msec = 200,
caused, got, i, id1, id2, j, re, show, story, state, $span;
if ( ! $div.length opt && = $floatOPTS.facet() "diff" ) {,
sign = Sign + "Difflink",
caused, got, i, id1, id2, j,
re, selector, shift, show, story, swap,
$a, $div, $span, $spanB, $spanE;
switch ( typeof opt ) {
case "boolean" :
break;
case "object" :
if ( opt ) {
if ( typeof opt.link === "boolean" ) {
link = opt.link;
}
if ( typeof opt.msec === "number" ) {
msec = opt.msec;
}
if ( typeof opt.selector === "string" ) {
selector = opt.selector;
}
} else {
opt = true;
}
break;
default :
opt = true;
} // switch typeof opt
if ( opt ) {
$div = $( "#" + sign );
if ( ! $div.length ) {
opt = $float( false, selector );
}
}
if ( opt ) {
if ( Env.wgCanonicalSpecialPageName ) {
// 2014 redirected to &diff=
Line 571 ⟶ 631:
if ( id1 ) {
Env.spcNS = mw.config.get( "wgFormattedNamespaces" )[ "-1" ];
storyif ( ! Env.wgPageName ) = ":Diff/" + id1{
Env.wgPageName = mw.config.get( "wgPageName" );
}
story = ":Diff/" + id1
+ ( id2 ? "/" + id2 : "" );
show shift = "[[" + Env.spcNS + story + "]]/wiki/";
$span = $ + mw.util.wikiUrlencode( "<span>"Env.spcNS ); + story
$span.text( show ); + "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
story = Env.spcNS + story;
$span = $( "<span>" );
if ( link ) {
$spanB = $( "<span>" );
$spanB.text( "[[" );
$a = $( "<a>" );
$a.attr( { "href": shift } );
$a.text( story );
$spanE = $( "<span>" );
$spanE.text( "]]" );
$span.append( $spanB );
$span.append( $a );
$span.append( $spanE );
} else {
$span.text( "[[" + story + "]]" );
}
$div = $factory( sign );
$div.append( $span );
Line 586 ⟶ 666:
fiat( false, "n" );
}
if ( ! link &&
typeof window.history.___replaceState === "function" ) {
if ( ! Env.wgPageName ) {
Env.wgPageName = mw.config.get( "wgPageName" );
}
state = "/wiki/"
+ mw.util.wikiUrlencode( Env.spcNS ) + story
+ "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
caused = { caused: Sign };
show = window.historydocument.___replaceState( caused,title;
if ( msec > 0 ) window.document.title,{
if ( id2 ) state );{
swap = shift + "&diff=" + id2 + "&oldid=" + id1;
} else {
swap = shift + "&diff=" + id1;
}
window.history.___replaceState( caused, show, swap );
window.setTimeout( feed, msec, caused, show, shift );
} else {
window.history.___replaceState( caused, show, shift );
}
}
}
Line 603 ⟶ 686:
freezer( true );
} // flip()
 
 
 
function forward( amount, alike ) {
// Convert links on page into Special: format
// Precondition:
// amount -- number of links per item to inspect
// alike -- if string "diff", required to occur
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.util.getParamValue()
// 2015-01-03 PerfektesChaos@de.wikipedia
var $results = $( "#mw-content-text li" ),
n = $results.length,
i, j, shift, special, start, strip, $a, $li;
if ( n ) {
special = "/wiki/"
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":";
for ( i = 0; i < n; i++ ) {
$li = $results.eq( i ).find( "a" );
for ( j = 0; j < amount; j++ ) {
$a = $li.eq( j );
strip = $a.attr( "href" );
start = mw.util.getParamValue( "oldid", strip );
if ( start ) {
strip = strip.replace( /&oldid=\d+\b/, "" )
.replace( /&curid=\d+\b/, "" );
shift = mw.util.getParamValue( "diff", strip );
if ( shift ) {
strip = strip.replace( /&diff=\d+\b/, "" );
shift = "Diff/" + start + "/" + shift;
} else if ( alike ) {
shift = false;
} else {
shift = "PermaLink/" + start;
}
if ( shift ) {
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
$a.attr( "href", strip );
}
}
} // for j
} // for i
}
} // forward()
 
 
Line 844 ⟶ 976:
// >< Env
// mw.util.getUrl()
// OPTS.facet()
// history.___pushState()
// history.___replaceState()
Line 858 ⟶ 990:
}
if ( ! last ) {
opts = OPTS.facet( "redirect" );
if ( opts &&
typeof opts === "object" &&
Line 880 ⟶ 1,012:
 
 
function further( amount ) {
// ConvertDeal linkswith onhistory page into Special: format
// Precondition:
// amount loaded --user.options number of links per item to inspectmediawiki.user
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.utiluser.getParamValueoptions.get()
// 20142015-1201-1403 PerfektesChaos@de.wikipedia
var $resultsn = $( "#mw-content-text li"= )3,
nopt = OPTS.facet( "history" = $results.length),
i, j, shift, special, start, strip, $a, $liscan;
switch ( typeof opt ) {
case "boolean" :
if ( opt === false ) {
n = 0;
}
break;
case "string" :
if ( opt === "diff" ) {
scan = "diff";
}
break;
} // switch opt
if ( n ) {
specialif ( scan === "/wiki/diff" ) {
n = 2;
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":";}
forif ( i = 0; i < n;mw.user.options.get( "gadget-navigation-popups" i++) ) {
$lin = $results.eq( i ).find( "a" )0;
}
for ( j = 0; j < amount; j++ ) {
if ( n $a >= $li.eq(1 j) );{
forward( n, strip = $a.attr( "href"scan );
}
start = mw.util.getParamValue( "oldid", strip );
if ( start ) {
strip = strip.replace( /&oldid=\d+\b/, "" )
.replace( /&curid=\d+\b/, "" );
shift = mw.util.getParamValue( "diff", strip );
if ( shift ) {
strip = strip.replace( /&diff=\d+\b/, "" );
shift = "Diff/" + start + "/" + shift;
} else {
shift = "PermanentLink/" + start;
}
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
$a.attr( "href", strip );
}
} // for j
} // for i
}
} // further()
Line 932 ⟶ 1,057:
// mw.config.get()
// mw.util.getParamValue()
// furtherforward()
// flip()
// further()
// freeze()
// freezer()
// fresh()
// from()
// OPTS.facet()
// fresher()
// freshest()
// flat()
// 20142015-1201-3003 PerfektesChaos@de.wikipedia
var linkUpdate;
Env = { skin: false,
Line 952 ⟶ 1,078:
switch ( Env.wgCanonicalSpecialPageName ) {
case "Contributions" :
furtherforward( 2 );
break;
case "Diff" :
Line 959 ⟶ 1,085:
case "Recentchanges" :
case "Watchlist" :
furtherforward( 1 );
break;
case "Gadgets" :
Line 975 ⟶ 1,101:
switch ( Env.wgAction ) {
case "history" :
further( 3 );
break;
case "view" :
Line 1,002 ⟶ 1,128:
} // switch wgAction
if ( linkUpdate ) {
if ( OPTS.facet( "forcelinkupdate" ) ) {
fresher( true );
}
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
freshest( true );
}
Line 1,011 ⟶ 1,137:
}
}
if ( OPTS.facet( "slangQQX" ) ) {
flat( true );
}
Line 1,020 ⟶ 1,146:
if ( mw.loader.getState( Signature ) !== "ready" ) {
mw.loader.state( Signature, "ready" );
mw.loaderuser.usingoptions.set( [ "mediawiki.utilgadget-" + Sign, Version );
mw.loader.using( [ "mediawiki.user" ],
"mediawiki.util",
"user",
"user.options" ],
function () {
$( fire ); // don't hurry