User:Bluefire272/common.js
Appearance
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. |
![]() | The accompanying .css page for this skin can be added at User:Bluefire272/common.css. |
$(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 id="temp" />');
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 [[User:Bluefire272\/Userboxes by me|here]]. If you want one on Wikia, go [http:\/\/www.runescape.wikia.com\/User:Bluefire2\/Userboxes here].\n\n{{boxboxtop|Userboxes}}\n{{Template:User BinaryPeople}}\n{{Template:User Pi}}\n{{User:FastLizard4\/Userboxing\/Russian Reversal}}\n{{User:Nefariousopus\/Userboxes\/DivideBy0}}\n{{User:Strdst grl\/ubx\/bouncing}}\n{{User:Strdst grl\/ubx\/mandelbrot}}\n{{User:Strdst grl\/ubx\/pointless anims}}\n{{boxboxbottom}}";
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 = $('<div id="caek">Hai</div>');
viewableText.html(html);
$(this).replaceWith(viewableText);
$(".break").remove();
$("#submit").remove();
$("#editlink").css("display", "inline");
$(viewableText).click(divToTextArea);
}
function divToTextArea(div) {
var textarea = $('<textarea />');
var submit = $('<button id="submit" onclick="textareaBlurred()">Submit</button>');
var br = $('<br class="break"/>');
var anotherBr = $('<br class="break"/>');;
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.');
}
});
}