< User:Alexis Jazz
Next edit → Content deleted Content addedInline
Revision as of 01:16, 9 October 2022
//SkinEnforcer (]) is a script to enforce a skin when you're not logged in. Or on the mobile site. (use MobileFrontend vectors like collapsible sections on Vector classic, yay!)
//SkinEnforcer is public domain, irrevocably released as WTFPL Version 2 by its author, Alexis Jazz.
//<nowiki>
/*globals $:false,mw:false*/
window.SENF = {};
var SENF = window.SENF;
SENF.go = function(UL){
console.log('SkinEnforcer: ALPHA JULIETT WE\'RE GOING IN');
UL=mw.config.get('wgUserLanguage');
SENF.addMenu = function(int,el) {
SENF.LM();
$('#SENF').remove();
if ( mw.config.get('skin') == 'minerva' && !$('#page-actions-overflow-toggle') ) {
el = document.createElement('li');
el.style = 'display:inline-block !important';
el.id = 'SENF';
el.innerHTML = '<a>'+SENF.m+'</a>';
$('#footer-places').append(el);
} else {
SENF.el = mw.util.addPortletLink(
'p-tb',
'#',
SENF.m,
'SENF',
SENF.m,
undefined,
'#t-specialpages'
);
}
SENF.menu = document.createElement('ul');
SENF.menu.id = 'SENFmenu';
SENF.menu.classList.add('SENFhidden');
for(int=0;int<Object.keys(SENF.m).length;int++){
SENF.mk = Object.keys(SENF.m);
SENF.mv = SENF.m;
if ( SENF.mk != 'prefs-skin' ) {
SENF.menulinks = (SENF.menulinks||'') + '<li><a id="SENF-'+SENF.mk+'" class="SENF">'+SENF.mv+'</a></li>';
}
}
SENF.menu.innerHTML = SENF.menulinks;
$('#SENF').append(SENF.menu);
$('#SENF a:eq(0)').on('click',function(event){
event.preventDefault();event.stopPropagation();
if ( $('#SENFmenu.SENFhidden') ) {
$('#SENFmenu').removeClass('SENFhidden');
$('#SENFmenu').scrollIntoView();
} else {
$('#SENFmenu').addClass('SENFhidden');
}
});
$('.SENF').on('click',function(event,s){
event.preventDefault();
s = event.delegateTarget.id.slice(5);
if ( s != mw.config.get('skin') ) {
SENF.skin = s;
if ( s == 'skin-action-delete' ) {
console.log('SkinEnforcer: ALPHA JULIETT WE LOST A MAN');
mw.storage.remove('SENF');
return;
}
mw.storage.set('SENF',s);
SENF.enforce(null,window.location.href);
} else {
$('#SENFmenu').removeClass('SENFhidden');
}
});
mw.util.addCSS('body.skin-minerva #SENFmenu>li{display:inline-block}.SENFhidden{display:none}#SENFmenu{font-size:inherit}body:not(.skin-monobook) #SENFmenu>li{cursor:pointer;margin-left:0.5em;margin-right:0.5em}body.skin-vector #SENFmenu>li,body.skin-vector-2022 #SENFmenu>li{font-size:larger}body.skin-minerva #SENFmenu>li{margin-top:1em}');
};
SENF.enforce = function(event,uri) {
uri = new mw.Uri((uri||event.delegateTarget.href));
uri.extend({useskin:SENF.skin});
console.log('SkinEnforcer: ALPHA JULIETT ATTACHED '+SENF.skin+' TO TARGET, TARGET SECURE, RETURN TO BASE');
window.location = uri.toString();
};
SENF.msgsEN = {'prefs-skin':'Skin',vector:'Vector','vector-2022':'Vector (2022)',minerva:'MinervaNeue',monobook:'Monobook',timeless:'Timeless',modern:'Modern',cologneblue:'Cologne Blue','skin-action-delete':'Delete'};
SENF.LM = function() {
try{SENF.m = JSON.parse(mw.storage.get('SENFLang'));} catch (e) {}
SENF.m = ( SENF.m || SENF.msgsEN );
};
SENF.getLang = function() {
SENF.LM();
if ( SENF.m.date && SENF.m.date < (new Date().getTime()-604800000) ) { //(7*24*3600*1000) cached lang >1 week old
mw.storage.remove('SENFLang');
}
if ( UL != 'en' && !mw.storage.get('SENFLang') ) {
var api = new mw.Api();
api.get( { format: 'json', action: 'query', meta: 'allmessages', amfilter:'skin', amlang:UL} ).done( function ( data,int,k,d,ek,m,msg ) {
d=data.query.allmessages;
m={};
m={};
for(int=0;int<d.length;int++){
ek=d.name;
if ( ek == 'prefs-skin' || ek == 'skin-action-delete' || (ek.match(/^skinname\-/) && ek != 'skinname-nostalgia' && ek != 'skinname-wikimediaapiportal') ) {
m = d;
}
}
mw.storage.set('SENFLang',JSON.stringify(m));
SENF.addMenu();
});
} else {
SENF.addMenu();
}
};
SENF.getLang();
SENF.skin = (mw.util.getParamValue('useskin') || (mw.storage.get('SENF') && mw.storage.get('SENF') != mw.config.get('skin') && mw.storage.get('SENF')));
if ( SENF.skin ) {
console.log('SkinEnforcer: ALPHA JULIETT REQUEST PERMISSION TO ENFORCE '+SENF.skin);
if ( mw.config.get('skin') != SENF.skin && !mw.util.getParamValue('useskin') ) { //you have a skin set in localStorage but it doesn't match your current skin
console.log('SkinEnforcer: ALPHA JULIETT DO YOU COPY WE HAVE A HOSTAGE SITUATION');
SENF.enforce(null,window.location.href);
}
$('a:not(.skin-minerva a#ca-edit)').on('click',function(event,ignoreEl,copyEl){
copyEl = document.createElement('span');
copyEl.append(event.delegateTarget.cloneNode());
ignoreEl = copyEl.querySelectorAll('.oo-ui-buttonElement-button,.mw-ui-button,#user-notifications,.minerva-talk-add-button,a#ca-watch,a#page-actions-overflow-toggle,a.language-selector');
if ( ignoreEl ) {
console.log('SkinEnforcer: ALPHA JULIETT FALSE ALARM, LINK IS EXPECTED TO PREVENTDEFAULT');
return;
}
if ( event.delegateTarget.href != '' && !event.delegateTarget.attributes.href.nodeValue.match(/^(http?:)?(\/\/|#)/) ) { //href-less link generally just triggers some event, external links and anchors on the current page should be left alone
event.preventDefault();event.stopPropagation();
console.log('SkinEnforcer: ALPHA JULIETT WE HAVE A VISUAL ON THE TARGET');
SENF.enforce(event);
}
});
}
};//SENF.go
mw.loader.using(,function(){SENF.go();});
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.
**DISCLAIMER** We are not affiliated with Wikipedia, and Cloudflare.
The information presented on this site is for general informational purposes only and does not constitute medical advice.
You should always have a personal consultation with a healthcare professional before making changes to your diet, medication, or exercise routine.
AI helps with the correspondence in our chat.
We participate in an affiliate program. If you buy something through a link, we may earn a commission 💕
↑