Advertisement
simpleruser

dw txt adder

Mar 12th, 2025
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         tmp txt adder
  3. // @namespace    http://pastebin.com/0smkg67S
  4. // @version      1.0
  5. // @description  hopefully does a thing
  6. // @author       icie
  7. // @match        *.dreamwidth.org/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11.  
  12. (
  13.  
  14.  
  15.     function() {
  16.         function addJQuery(callback) {
  17.     var script = document.createElement("script");
  18.     script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  19.     script.addEventListener('load', function() {
  20.         var script = document.createElement("script");
  21.         script.textContent = "window.$=jQuery.noConflict(true);(" + callback.toString() + ")();";
  22.         document.body.appendChild(script);
  23.     }, false);
  24.     document.body.appendChild(script);
  25. }
  26.  
  27. function main(){
  28.     var textcodestart = '<span style="font-family:courier new">';
  29.     var textcodeend = '</span>';
  30.     var actioncodestart = '<small>[';
  31.     var actioncodeend = ']</small>';
  32.     var count = 0;
  33.  
  34.     function addText(sStartTag, sEndTag) {
  35.         var bDouble = arguments.length > 1, oMsgInput = $('[name="body"]:first')[0], nSelStart = oMsgInput.selectionStart, nSelEnd = oMsgInput.selectionEnd, sOldText = oMsgInput.value;
  36.         oMsgInput.value = sOldText.substring(0, nSelStart) + (bDouble ? sStartTag + sOldText.substring(nSelStart, nSelEnd) + sEndTag : sStartTag) + sOldText.substring(nSelEnd);
  37.         oMsgInput.setSelectionRange(bDouble || nSelStart === nSelEnd ? nSelStart + sStartTag.length : nSelStart, (bDouble ? nSelEnd : nSelStart) + sStartTag.length);
  38.         oMsgInput.focus();
  39.     }
  40.  
  41.     function addtextcode(){
  42.         addText(textcodestart, textcodeend);
  43.     }
  44.  
  45.     function addactioncode(){
  46.         addText(actioncodestart, actioncodeend);
  47.     }
  48.  
  49.     $('#subject').after($('<button></button>').prop('id','txtbtn').prop('type','button').text('TXT').click(addtextcode));
  50.     $('#subject').after($('<button></button>').prop('id','actionbtn').prop('type','button').text('ACTION').click(addactioncode));
  51. //$('head').append($('<meta name="viewport" content="width=device-width, initial-scale=1.0"> '));
  52. //$('img').css('max-width','100%'); $('.dwexpcomment').css('margin-left','0');
  53.  
  54. }
  55. window.onload = function() {
  56.     if (window.jQuery) {
  57.         // jQuery is loaded
  58.        // alert("Yeah!");
  59.         main();
  60.     } else {
  61.         // jQuery is not loaded
  62.         addJQuery(main)
  63.     }
  64. }
  65. //addJQuery(main);
  66. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement