Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name tmp txt adder
- // @namespace http://pastebin.com/0smkg67S
- // @version 1.0
- // @description hopefully does a thing
- // @author icie
- // @match *.dreamwidth.org/*
- // @grant none
- // ==/UserScript==
- (
- function() {
- function addJQuery(callback) {
- var script = document.createElement("script");
- script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
- script.addEventListener('load', function() {
- var script = document.createElement("script");
- script.textContent = "window.$=jQuery.noConflict(true);(" + callback.toString() + ")();";
- document.body.appendChild(script);
- }, false);
- document.body.appendChild(script);
- }
- function main(){
- var textcodestart = '<span style="font-family:courier new">';
- var textcodeend = '</span>';
- var actioncodestart = '<small>[';
- var actioncodeend = ']</small>';
- var count = 0;
- function addText(sStartTag, sEndTag) {
- var bDouble = arguments.length > 1, oMsgInput = $('[name="body"]:first')[0], nSelStart = oMsgInput.selectionStart, nSelEnd = oMsgInput.selectionEnd, sOldText = oMsgInput.value;
- oMsgInput.value = sOldText.substring(0, nSelStart) + (bDouble ? sStartTag + sOldText.substring(nSelStart, nSelEnd) + sEndTag : sStartTag) + sOldText.substring(nSelEnd);
- oMsgInput.setSelectionRange(bDouble || nSelStart === nSelEnd ? nSelStart + sStartTag.length : nSelStart, (bDouble ? nSelEnd : nSelStart) + sStartTag.length);
- oMsgInput.focus();
- }
- function addtextcode(){
- addText(textcodestart, textcodeend);
- }
- function addactioncode(){
- addText(actioncodestart, actioncodeend);
- }
- $('#subject').after($('<button></button>').prop('id','txtbtn').prop('type','button').text('TXT').click(addtextcode));
- $('#subject').after($('<button></button>').prop('id','actionbtn').prop('type','button').text('ACTION').click(addactioncode));
- //$('head').append($('<meta name="viewport" content="width=device-width, initial-scale=1.0"> '));
- //$('img').css('max-width','100%'); $('.dwexpcomment').css('margin-left','0');
- }
- window.onload = function() {
- if (window.jQuery) {
- // jQuery is loaded
- // alert("Yeah!");
- main();
- } else {
- // jQuery is not loaded
- addJQuery(main)
- }
- }
- //addJQuery(main);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement