User:Beleg Tâl/Sonnets.js

// /* 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\n\n\n\n## ' + opage + ' ##\n\n\n\n'); }	}); });

$.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 ('');            }); }	}); });

$.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('\n\n'); }	}); });

$.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\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, ' \n'); editor.set('\n\n\n'+content+'\n\n'); }	}); });

//