User:Bluefire272/common.js

$(document).ready(function {   $("a[title^='Edit section']").each(function(i) { $(this).addClass("pair" + i); $(this).attr("href", null); $(this).attr("onclick", "sectionToTextarea($(this))"); $(this).closest("h1, h2, h3, h4, h5, h6").addClass("pair" + i); $(this).closest("p").addClass("pair" + i); }); }); var viewableText;

function sectionToTextarea(editlink) { var c = editlink.attr("class"); var sectionNumber = c.charAt(c.length - 1); var textarea = $(' '); textarea.val = "== Another test ==\nAnother cake\n\n=== Small test ===\nSmall cake\n\nHello everyone, I am yet another new addition to Wikipedia! I have a bit (I mean a bit) of wiki experience most of which comes from being quite active on Wikia, specifically the RuneScape wiki. [http:\/\/www.runescape.wikia.com\/User:Bluefire2 This] is my RSW account. If you would like to request a userbox, please go here. If you want one on Wikia, go [http:\/\/www.runescape.wikia.com\/User:Bluefire2\/Userboxes here].\n\n\n\n\n\n\n\n\n\n"; var a = editlink; var p = $("p." + c); var header = $("." + c).filter(":header"); //a.remove; header.remove; p.replaceWith(textarea); } function textareaBlurred { var html = $(this).val; //viewableText = $(' Hai '); viewableText.html(html); $(this).replaceWith(viewableText); $(".break").remove; $("#submit").remove; $("#editlink").css("display", "inline"); $(viewableText).click(divToTextArea); }

function divToTextArea(div) { var textarea = $(' '); var submit = $('Submit '); var br = $(' '); var anotherBr = $(' ');; var divHTML = div.html; textarea.val(divHTML); matchProperties(div, textarea); div.replaceWith(textarea); br.insertAfter(textarea); submit.insertAfter(br); anotherBr.insertAfter(submit); $("#editlink").css("display", "none"); textarea.focus; textarea.blur(textareaBlurred); }

function matchProperties(div, textarea) { var height = div.css("height"); height = height.substring(0, height.length - 2); height = parseInt(height); var newHeight = height + parseInt(div.css("borderWidth")); textarea.css("height", newHeight); textarea.css("width", div.css("width")); textarea.css("position", div.css("position")); }

function getSectionText(page, section) { $.getJSON(       'http://en.wikipedia.org/w/api.php?', {            action: 'query',			prop: 'revisions',			rvlimit: '1',			rvsection: section,			rvprop: 'content',			format: 'xml',			titles: page        },		function(data) {			return data;		}    ) }

function editSection(summary, content, section) { $.ajax({       url: mw.util.wikiScript('api'),        data: {            format: 'json',            action: 'edit',            title: mw.config.get('wgPageName'),            section: '1',            summary: summary,            text: content,            token: mw.user.tokens.get('csrfToken')        },        dataType: 'json',        type: 'POST',        success: function(data) {            if (data && data.edit && data.edit.result == 'Success') {				window.location.reload;            } else if (data && data.error) {                alert('Error: API returned error code "' + data.error.code + '": ' + data.error.info);            } else {                alert('Error: Unknown result from API.');            }        },        error: function(xhr) {            alert('Error: Request failed.');        }    }); }