summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2017-05-21 00:24:03 -0700
committermatthewsotoudeh <matthewsot@outlook.com>2017-05-21 00:24:03 -0700
commit3e30627cbe1dc4c809fd7552c56c44aeb98e83a0 (patch)
tree2d7dec1a83c2de968f5381c2db5c12ca1b5d4da9
parentb07bc94dd445a3d7321a9a004c95690836c649d2 (diff)
updated with latest version of docs+
also added a gitignore
-rw-r--r--.gitignore3
-rw-r--r--docs.js68
-rw-r--r--utils.js14
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
+*~
diff --git a/docs.js b/docs.js
index be19ca6..09df9f3 100644
--- a/docs.js
+++ b/docs.js
@@ -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;
diff --git a/utils.js b/utils.js
index 2d4d913..6ab223b 100644
--- a/utils.js
+++ b/utils.js
@@ -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
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback