diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2017-05-21 00:24:03 -0700 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2017-05-21 00:24:03 -0700 |
commit | 3e30627cbe1dc4c809fd7552c56c44aeb98e83a0 (patch) | |
tree | 2d7dec1a83c2de968f5381c2db5c12ca1b5d4da9 | |
parent | b07bc94dd445a3d7321a9a004c95690836c649d2 (diff) |
updated with latest version of docs+
also added a gitignore
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | docs.js | 68 | ||||
-rw-r--r-- | utils.js | 14 |
3 files changed, 51 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53b7af4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.swo +*~ @@ -53,7 +53,7 @@ docs.getSelectionWithObserver = function (callback, defaultToParagraph, getRaw) docs.getSelection = docs.getSelectionWithObserver; docs.runWithCreateKeyboard = function (strToRun, funcName, params) { - var toRun = "var utils = {};utils.createKeyboardEvent = " + utils.createKeyboardEvent.toString() + ";"; + var toRun = "var docs = {'utils': {}};docs.utils.createKeyboardEvent = " + docs.utils.createKeyboardEvent.toString() + ";"; toRun += strToRun; @@ -63,10 +63,6 @@ docs.runWithCreateKeyboard = function (strToRun, funcName, params) { }; docs.insertText = function (toInsert) { - /*function coolerDoInsert(toInsert) { - var e = new ClipboardEvent('paste', { dataType: 'text/plain', data: toInsert }); - document.getElementsByClassName("docs-texteventtarget-iframe")[0].contentWindow.document.querySelector("[contenteditable=\"true\"]").dispatchEvent(e); - }*/ function doInsertText(toInsert) { for (var i = 0; i < toInsert.length; i++) { var key = toInsert[i]; @@ -131,7 +127,7 @@ docs.backspace = function (counts) { var secondsTimeout = secondsSinceLastBackspace < 1 ? (1 - secondsSinceLastBackspace) : 0; - var toRun = "var utils = {};utils.createKeyboardEvent = " + utils.createKeyboardEvent.toString() + ";"; + var toRun = "var docs = {'utils': {}};docs.utils.createKeyboardEvent = " + docs.utils.createKeyboardEvent.toString() + ";"; toRun += doBackspace.toString(); @@ -160,7 +156,7 @@ docs.setColor = function (colorSelector) { el.dispatchEvent(new MouseEvent("mouseleave", { bubbles: true })); }; -docs.toggleSubscript = function () { +docs.ctrlKeyShortcut = function (secondKey) { function _doToggleSubscript() { var ctrl = { "key": "Control", @@ -173,44 +169,66 @@ docs.toggleSubscript = function () { "which": 17, "ctrlKey": true }; - var comma = { - "key": ",", - "charCode": 0, - "keyCode": 188, - "bubbles": true, - "cancelable": true, - "code": 188, - "pageY": 7, - "which": 188, - "ctrlKey": true - }; var ctrlDown = docs.utils.createKeyboardEvent("keydown", ctrl); - var commaDown = docs.utils.createKeyboardEvent("keydown", comma); - var commaUp = docs.utils.createKeyboardEvent("keyup", comma); - var commaPress = docs.utils.createKeyboardEvent("keypress", comma); + var secondDown = docs.utils.createKeyboardEvent("keydown", secondKey); + var secondUp = docs.utils.createKeyboardEvent("keyup", secondKey); + var secondPress = docs.utils.createKeyboardEvent("keypress", secondKey); var ctrlUp = docs.utils.createKeyboardEvent("keydown", ctrl); var ctrlPress = docs.utils.createKeyboardEvent("keypress", ctrl); var el = document.getElementsByClassName("docs-texteventtarget-iframe")[0].contentWindow.document.querySelector("[contenteditable=\"true\"]"); el.dispatchEvent(ctrlDown); - el.dispatchEvent(commaDown); - el.dispatchEvent(commaUp); - el.dispatchEvent(commaPress); + el.dispatchEvent(secondDown); + el.dispatchEvent(secondUp); + el.dispatchEvent(secondPress); el.dispatchEvent(ctrlUp); el.dispatchEvent(ctrlPress); } if (docs.platform !== "userscript") { - docs.runWithCreateKeyboard(_doToggleSubscript.toString(), "_doToggleSubscript", ""); + function escape_quotes(str) { + //TODO: something that's not practically guaranteed to break here + return str.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"") + } + docs.runWithCreateKeyboard("secondKey=JSON.parse(\"" + escape_quotes(JSON.stringify(secondKey)) + "\");" + _doToggleSubscript.toString(), "_doToggleSubscript", ""); return; } else { _doToggleSubscript(); } }; +docs.toggleSubscript = function () { + var comma = { + "key": ",", + "charCode": 0, + "keyCode": 188, + "bubbles": true, + "cancelable": true, + "code": 188, + "pageY": 7, + "which": 188, + "ctrlKey": true + }; + docs.ctrlKeyShortcut(comma); +}; +docs.toggleBold = function () { + var b = { + "key": "b", + "charCode": 0, + "keyCode": 66, + "bubbles": true, + "cancelable": true, + "code": 66, + "pageY": 7, + "which": 66, + "ctrlKey": true + }; + docs.ctrlKeyShortcut(b); +}; + docs.getCurrentParagraphText = function(callback) { //Set up an observer to observe all the paragraphs var calledAlready = false; @@ -65,15 +65,11 @@ docs.utils.createKeyboardEvent = function (type, info) { } docs.utils.runInPage = function (script) { - if (actionPluginPlatform === "firefox") { - var th = document.body; - var s = document.createElement('script'); - s.setAttribute('type', 'text/javascript'); - s.innerHTML = script; - th.appendChild(s); - return; - } - window.location = "javascript:" + script; + var th = document.body; + var s = document.createElement('script'); + s.setAttribute('type', 'text/javascript'); + s.innerHTML = script; + th.appendChild(s); }; //Thanks! https://stackoverflow.com/questions/1740700/how-to-get-hex-color-value-rather-than-rgb-value |