Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- //
- // @name HSTextadder
- // @description Adds the html for all characters to text boxes
- // @author SimplerUser
- // @version 1.4.1
- // @include http://*.dreamwidth.org/*
- //
- // ==/UserScript==
- //edit for ff users by janekptacijarabaci
- function detect_txtbx() {
- var txtbx = document.getElementById("body") || document.getElementById("commenttext");
- if (txtbx != null){
- clearInterval(timer);
- //get the currentusername
- var length = document.getElementsByClassName("ljuser").length;
- var user = document.getElementsByClassName("ljuser")[length-1].getAttribute("lj:user");
- var usermap = new Array('baby', 'poop', 'sexy', 'crab', 'monster'); //list of usernames
- var charactermap = new Array('Text', 'Audio', 'Voicemail', 'Courier', 'Colored');
- //characters they match to
- var character = "";
- for (var i = 0 ; i < usermap.length; i++){ //set character to username
- if (usermap[i] == user) {
- character = charactermap[i];
- }
- }
- //hs characters and their codes
- var htmlcharmap = new Array( 'Courier', 'Colored', 'Text', 'Audio', 'Voicemail');
- var htmlmap = new Array(
- '<span style="font-family:courier;">',
- '<span style="font-family:courier; color:#5e5a63;">',
- '<span style="font-family:courier;"><B>FROM:</B> whoever@whatever.org<br/><b>TO:</B> whoever@whatever.org',
- '<span style="font-family:courier;"><B>CALLING:</B> LAST NAME, FIRST NAME</span>',
- '<span style="font-family:courier;"><B>(1) VOICEMAIL:</B> LAST NAME, FIRST NAME</span>');
- var list = document.createElement('select');
- list.setAttribute('id', 'charList');
- for (var i = 0; i < htmlcharmap.length; i++){
- var nameEl = document.createElement('option');
- nameEl.setAttribute('value', htmlmap[i]);
- nameEl.innerHTML = htmlcharmap[i];
- if (htmlcharmap[i] == character) {
- nameEl.setAttribute('selected', 'selected');
- }
- list.appendChild(nameEl);
- }
- function insertAfter(newElement,targetElement) {
- var parent = targetElement.parentNode;
- if(parent.lastchild == targetElement) {
- parent.appendChild(newElement);
- } else {
- parent.insertBefore(newElement, targetElement.nextSibling);
- }
- }
- //make the button
- var zNode = document.createElement ('button');
- zNode.setAttribute ('id', 'myButton');
- zNode.setAttribute ('type', 'button');
- zNode.innerHTML = 'Add Code';
- //make the button
- var end = document.createElement ('button');
- end.setAttribute ('id', 'endButton');
- end.setAttribute ('type', 'button');
- end.innerHTML = 'close tags';
- //make the button
- var act = document.createElement ('button');
- act.setAttribute ('id', 'actButton');
- act.setAttribute ('type', 'button');
- act.innerHTML = 'small tags';
- insertAfter(list, document.getElementById("subject"));
- insertAfter(zNode, document.getElementById("charList"));
- insertAfter(end, document.getElementById("myButton"));
- insertAfter(act, document.getElementById("endButton"));
- function doGetCaretPosition (ctrl) {
- var CaretPos = 0; // IE Support
- if (document.selection) {
- ctrl.focus ();
- var Sel = document.selection.createRange ();
- Sel.moveStart ('character', -ctrl.value.length);
- CaretPos = Sel.text.length;
- }
- // Firefox support
- else if (ctrl.selectionStart || ctrl.selectionStart == '0')
- CaretPos = ctrl.selectionStart;
- return (CaretPos);
- }
- function setCaretPosition(ctrl, pos){
- if(ctrl.setSelectionRange)
- {
- ctrl.focus();
- ctrl.setSelectionRange(pos,pos);
- }
- else if (ctrl.createTextRange) {
- var range = ctrl.createTextRange();
- range.collapse(true);
- range.moveEnd('character', pos);
- range.moveStart('character', pos);
- range.select();
- }
- }
- function ButtonClickAction (zEvent)
- {
- html = document.getElementById('charList').value
- var curPos = doGetCaretPosition(txtbx);
- var curVal = txtbx.value;
- txtbx.value = curVal.substring(0, curPos) + html + curVal.substring(curPos); //adds the stuff
- setCaretPosition(txtbx, curPos + html.length);
- }
- function EndButtonClickAction (zEvent)
- {
- var toAdd = '</span>';
- var curPos = doGetCaretPosition(txtbx);
- var curVal = txtbx.value;
- txtbx.value = curVal.substring(0, curPos) + toAdd + curVal.substring(curPos); //adds the stuff
- setCaretPosition(txtbx, curPos + toAdd.length);
- }
- function ActButtonClickAction (zEvent)
- {
- var toAdd = '<small>[]</small>';
- var curPos = doGetCaretPosition(txtbx);
- var curVal = txtbx.value;
- txtbx.value = curVal.substring(0, curPos) + toAdd + curVal.substring(curPos); //adds the stuff
- setCaretPosition(txtbx, curPos + 8);
- }
- //--- Activate the newly added button.
- document.getElementById ("myButton").addEventListener ("click", ButtonClickAction, false);
- document.getElementById ("endButton").addEventListener ("click", EndButtonClickAction, false);
- document.getElementById ("actButton").addEventListener ("click", ActButtonClickAction, false);
- }
- }
- timer = setInterval(detect_txtbx, 100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement