Last active
December 16, 2015 02:49
-
-
Save boxmein/5365649 to your computer and use it in GitHub Desktop.
Rewrites TPT quoting to a minimal and much more 'embedded' kind of quote. It isn't huge and it combines the reply function as well, also reducing markup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint browser: true, jquery: true */ | |
/*global GetQuote*/ | |
function getSelectionHtml() { | |
var html = ''; | |
if (typeof window.getSelection != 'undefined') { | |
var sel = window.getSelection(); | |
if (sel.rangeCount) { | |
var container = document.createElement('div'); | |
for (var i = 0, len = sel.rangeCount; i < len; ++i) { | |
container.appendChild(sel.getRangeAt(i).cloneContents()); | |
} | |
html = container.innerHTML; | |
} | |
} else if (typeof document.selection != 'undefined') { | |
if (document.selection.type == 'Text') { | |
html = document.selection.createRange().htmlText; | |
} | |
} | |
return html; | |
} | |
GetQuote = function (PostID, Element, Username){ | |
$('html, body').animate({scrollTop: $(document).height()}, 200); | |
$('#AddReplyMessage.EditPlain').insertAtCaret('@' + Username + '!' + PostID + '\n<em>>' + getSelectionHtml() + '</em>'); | |
$('#AddReplyMessage.EditWYSIWYG').tinymce().execCommand('mceInsertContent',false, '@' + Username + '<br />\n<em>>' + getSelectionHtml() + '</em>'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name The Powder Toy quotes rewrite | |
// @namespace http://github.com/boxmein | |
// @version 0.1.2 | |
// @description Rewrites the quote function to do an entirely different thing. See if it works! :D | |
// @match http://powdertoy.co.uk/* | |
// @copyright 2013+, boxmein | |
// ==/UserScript== | |
// Install me here: http://userscripts.org/scripts/show/164774 | |
/*global jQuery,$,GetQuote,Element */ | |
/*jshint browser:true, multistr:true */ | |
// Here's where the magic happens. See additional file. | |
var magicaljs = "function getSelectionHtml(){var a='';if('undefined'!=typeof window.getSelection){var c=window.getSelection();if(c.rangeCount){for(var a=document.createElement('div'),b=0,d=c.rangeCount;b<d;++b)a.appendChild(c.getRangeAt(b).cloneContents());a=a.innerHTML}}else'undefined'!=typeof document.selection&&'Text'==document.selection.type&&(a=document.selection.createRange().htmlText);return a} GetQuote=function(a,c,b){$('html, body').animate({scrollTop:$(document).height()},200);$.get('/Discussions/Thread/Post.json?Type=Raw&Post='+a,function(c){1==c.Status?($('#AddReplyMessage.EditPlain').insertAtCaret('@'+b+'!'+a+'\\n<em>>'+getSelectionHtml()+'</em>'),$('#AddReplyMessage.EditWYSIWYG').tinymce().execCommand('mceInsertContent',!1,'@'+b+'<br />\\n<em>>'+getSelectionHtml()+'</em>')):($('#AddReplyMessage.EditPlain').insertAtCaret('@'+b+'!'+a+'\\n<em>>'+getSelectionHtml()+'</em>'),$('#AddReplyMessage.EditWYSIWYG').tinymce().execCommand('mceInsertContent',!1,'@'+b+'!'+a+'<br />\\n<em>>'+getSelectionHtml()+'</em>'))})};"; | |
// Very simple element injection. | |
var js = document.createElement("script"); | |
js.text = magicaljs; | |
document.body.appendChild(js); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment