Jump to content

User:Beleg Tâl/Sonnets.js

From Wikisource
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// <nowiki>
/*
function romanize (num) {
    if (isNaN(num))
        return NaN;
    var digits = String(+num).split(""),
        key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
               "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
               "","I","II","III","IV","V","VI","VII","VIII","IX"],
        roman = "",
        i = 3;
    while (i--)
        roman = (key[+digits.pop() + (i * 10)] || "") + roman;
    return Array(+digits.join("") + 1).join("M") + roman;
}

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
		name: 'Sonnets Pagespace',
		category: 'Page tools',
    	script: function(editor) {
    		var pn    = /\.djvu\/([0-9]+)&action=edit/g.exec(location.href);
		    var page  = pn !== null ? parseInt(pn[1], 10) : null;
		    var epage = 2*(page-53);
		    var opage = epage+ 1;
		    
		    editor.set('## ' + epage + ' ##\n{{c|' + romanize(epage) + '.}}\n\n{{center block|}}\n\n## ' + opage + ' ##\n{{c|' + romanize(opage) + '.}}\n\n{{center block|}}\n{{nop}}');
		}
	});
});

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
		name: 'Sonnets Mainspace',
		category: 'Page tools',
    	script: function(editor) {
    		var sonnetIDRegEx = /\s\d+/;
    		var sonnetID      = parseInt($.trim(sonnetIDRegEx.exec(mw.config.get('wgTitle'))));
    		var page          = parseInt(sonnetID / 2) + 53;

            editor.replaceSelection(function(text) {
    		    return ('<pages index="Shakespeare\'s Sonnets.djvu" include=' + page + ' onlysection=' + sonnetID + ' />');
            });
		}
	});
});

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
		name: 'Fidessa',
		category: 'Page tools',
    	script: function(editor) {
    		var sonnetIDRegEx = /\d+/;
    		var sonnetID      = parseInt($.trim(sonnetIDRegEx.exec(mw.config.get('wgTitle'))));
    		var next          = sonnetID + 1;
    		var prev          = sonnetID - 1;
    		var page          = sonnetID + 84;

            editor.set('{{header\n | title      = [[../../|Elizabethan Sonnet-Cycles]]\n | author     = | editor = Martha Foote Crow\n | translator = \n | section    = [[../|Fidessa]], Sonnet '+sonnetID+'\n | contributor= Bartholomew Griffin\n | previous   = [[../'+prev+'|Sonnet '+prev+']]\n | next       = [[../'+next+'|Sonnet '+next+']]\n | year       = 1897\n | notes      = \n}}\n\n<pages index="Elizabethan sonnet-cycles.djvu" include='+page+' />');
		}
	});
});

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
		name: 'DiaryHeader',
		category: 'Page tools',
    	script: function(editor) {
			editor.replaceSelection(function(text) {
				return '\n\n{{ul|\'\'' + text + '\'\'}}\n\n';
			});
    	}
	});
});

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add({
		name: 'Nonsense',
		category: 'Page tools',
    	script: function(editor) {
    		var pn    = /\.djvu\/([0-9]+)&action=edit/g.exec(location.href);
		    var page  = pn !== null ? parseInt(pn[1], 10) : null;
		    var poem  = page - 16;
		    
		    var content = editor.getText();
		    
		    content.replace(/\n/g, '<br />\n');
		    
		    editor.set('[[File:Edward Lear A Book of Nonsense '+poem+'.jpg|center|300px]]\n\n{{center block|\n'+content+'\n}}\n{{nop}}');
		}
	});
});

*/
// </nowiki>