Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var form = null;
- var position;
- var cursor;
- var currentURL = "";
- var isListening = 0;
- check();
- window.setInterval("check();", 250);
- chrome.extension.onConnect.addListener( function(port)
- {
- port.onMessage.addListener(function (string)
- {
- if(string != "")
- {
- form.value = form.value.substring(0, position+1) + string + form.value.substring(cursor+1,form.value.length);
- form.setSelectionRange(position+1+string.length,position+1+string.length);
- }
- });
- });
- function keydown(event)
- {
- if(event.which == 32 && event.ctrlKey)
- parse(form.value);
- }
- function check()
- {
- if(form == null)
- {
- form = document.getElementById("tickets_reply");
- if(form != null)
- {
- if(isListening)
- form.removeEventListener("keypress",keydown);
- form.addEventListener("keypress",keydown);
- isListening = 1;
- }
- currentURL = window.location.href;
- }
- if(window.location.href != currentURL)
- {
- form = null;
- isListening = 0;
- }
- }
- function parse(string)
- {
- cursor = form.selectionStart;
- string = string.substring(0,cursor);
- position = Math.max(
- string.lastIndexOf("."),
- string.lastIndexOf("\n"),
- string.lastIndexOf("?"),
- string.lastIndexOf("!"));
- while(string[position+1] == ' ')
- position++;
- string = string.substring(position + 1,string.length);
- var port = chrome.runtime.connect();
- port.postMessage(string);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement