User:Alexis Jazz/Factotum/modules/POTD.js
Appearance
< User:Alexis Jazz | Factotum
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. |
![]() | Documentation for this user script can be added at User:Alexis Jazz/Factotum/modules/POTD. |
//POTDModule loads the Picture of the Day (according to Template:POTD) as the background image for Factotum.
//To load the POTD from another wiki, either put window.FTTPOTDDomain in your common.js with the desired domain (e.g. window.FTTPOTDDomain = 'wiki.riteme.site'; ) or set that domain in the custom background field.
//POTDModule is public domain, irrevocably released as WTFPL Version 2[www.wtfpl.net/about/] by its author, Alexis Jazz.<nowiki>
//To load this script add this to your common.js or global.js:
//mw.loader.load('//wiki.riteme.site/w/index.php?title=User:Alexis Jazz/Factotum/POTDModule.js&action=raw&ctype=text/javascript');
if ( ! window.FTTModules ) { window.FTTModules=[]; }
window.FTTModules.push({'load':['afterOpenForm'],'buttonLabel':'POTD','buttonId':'FTTPOTDBTN','buttonFunc':function(){FTT.popup('<div style="text-align:center;min-height:20em">'+FTT.MD.POTDBG.LS[(window.FTTPOTDDomain || FTT.settings.customBackground || mw.config.get('wgServerName'))].POTD+'</div>');},
'afterOpenFormFunc':function(){
FTT.MD.POTDBG = {};
FTT.MD.POTDBG.domain = ( window.FTTPOTDDomain || ( FTT.settings.customBackground != '' && !FTT.settings.customBackground.match(/:\/\//) && FTT.settings.customBackground ) || mw.config.get('wgServerName') );
FTT.MD.POTDBG.date = new Date();
FTT.MD.POTDBG.date = FTT.MD.POTDBG.date.getUTCFullYear().toString() + '-' + (FTT.MD.POTDBG.date.getUTCMonth()+1).toString() + '-' + FTT.MD.POTDBG.date.getUTCDate().toString();
FTT.MD.POTDBG.LS = FTT.testValidJSON(FTT.getItemLS('FTTPOTD'));
if ( FTT.MD.POTDBG.LS && FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain] && FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain].date == FTT.MD.POTDBG.date ) {
if ( FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain].link ) {
FTT.setCustomBackground(FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain].link);
}
} else {
FTT.MD.POTDBG.save = function(data,int) {
FTT.MD.POTDBG.LS = {};
FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain] = {date:FTT.MD.POTDBG.date,POTD:data.parse.text['*']};
$('body').append('<div id="FTTPOTD" class="FTTPOTD FTTNoDisplay">'+data.parse.text['*']+'</div>');
for (int=0;int<$('#FTTPOTD img').length;int++) {
if ( ($('#FTTPOTD img')[int].height * $('#FTTPOTD img')[int].width) > 10000 ) { //check if the image is a certain size so we don't match little icons
FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain].link = $('#FTTPOTD img')[int].src.replace(/\/[0-9]+px\-/,'/1024px-');
FTT.setItemLS('FTTPOTD',FTT.deflate(FTT.MD.POTDBG.LS,'forceUTF16'));
FTT.setCustomBackground(FTT.MD.POTDBG.LS[FTT.MD.POTDBG.domain].link);
$('#FTTPOTD').remove();
break;
}
}
};
mw.loader.using(['mediawiki.ForeignApi'], function(){
var apiBGWD = new mw.ForeignApi('https://www.wikidata.org'+mw.config.get('wgScriptPath')+'/api.php',{anonymous:true});
apiBGWD.post( {format:'json',action:'wbgetentities',props:'sitelinks',ids:'Q14334596'} ).then( function ( data ) {
FTT.MD.POTDBG.template = data.entities.Q14334596.sitelinks[FTT.MD.POTDBG.domain.replace(/\.wikipedia\.org/,'wiki').replace(/\.wikipedia\.org/,'wiki').replace(/\.wiki(news|voyage|books|source|quote|versity)\.org/,'wiki$1').replace(/\.wiktionary\.org/,'wiktionary').replace(/commons\.wikimedia\.org/,'commonswiki')];
if ( !FTT.MD.POTDBG.template ) {
mw.notify('No picture of the day found for '+FTT.MD.POTDBG.domain);
$('#FTTPOTDBTN').addClass('FTTNoDisplay');
return;
}
FTT.MD.POTDBG.templatetitle = FTT.MD.POTDBG.template.title;
var apiBG = new mw.ForeignApi('https://'+FTT.MD.POTDBG.domain+mw.config.get('wgScriptPath')+'/api.php',{anonymous:true});
FTT.MD.POTDBG.params = {format: 'json', contentmodel:'wikitext', action: 'parse', pst:1, disablelimitreport: true, text: '{{ '+FTT.MD.POTDBG.templatetitle+' }}'};
apiBG.post( FTT.MD.POTDBG.params ).then( function ( data ) {
FTT.MD.POTDBG.save(data);
});
});
});
}
}});
//</nowiki>