summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2017-02-04 21:22:17 -0800
committermatthewsotoudeh <matthewsot@outlook.com>2017-02-04 21:22:17 -0800
commit1c3bd31565bd1d6a42015eb5f16a6c0885a5468a (patch)
treea610768c54d3714b8a01f78916bb4e6e8404512e
parentd782c79ea9f163a2a4bfd72261ab83a4ca3cf683 (diff)
updated with the docs-plus scripts
-rw-r--r--docs.js17
-rw-r--r--utils.js27
2 files changed, 32 insertions, 12 deletions
diff --git a/docs.js b/docs.js
index c3b84d3..72c6a46 100644
--- a/docs.js
+++ b/docs.js
@@ -1,8 +1,9 @@
-var docs = {
+var docs = docs || { //TODO: cleanup the duplication here + in utils.js
id: window.location.href.split("/document/d/")[1].split("/")[0],
get name() {
return $(".docs-title-input-label-inner").text().trim();
- }
+ },
+ platform: "chrome" //chrome, firefox, userscript
};
docs.getSelectionEl = function () {
@@ -41,7 +42,7 @@ docs.getSelectionWithObserver = function (callback, defaultToParagraph, getRaw)
utils.observe($(".docs-texteventtarget-iframe").contents().find("[contenteditable=\"true\"]")[0], {
childList: true
- }, function (mutations) {
+ }, function(mutations) {
callback(getRaw ? mutations[0].target : $(mutations[0].target).text().trim());
}, true);
@@ -89,14 +90,14 @@ docs.insertText = function (toInsert) {
}
}
- if (actionPluginPlatform !== "userscript") {
+ if (docs.platform !== "userscript") {
docs.runWithCreateKeyboard(doInsertText.toString(), "doInsertText", "\"" + toInsert + "\"");
} else {
doInsertText(toInsert);
}
};
-var lastBackspace = Date.now();
+docs.lastBackspace = Date.now();
docs.backspace = function (counts) {
function doBackspace(counts) {
var keyboardType = "keypress";
@@ -122,7 +123,7 @@ docs.backspace = function (counts) {
if (typeof counts === "undefined") counts = 1;
- var secondsSinceLastBackspace = (Date.now() - lastBackspace) / 1000;
+ var secondsSinceLastBackspace = (Date.now() - docs.lastBackspace) / 1000;
if (counts === 1 && secondsSinceLastBackspace < 1) return; //just trust me here
@@ -202,7 +203,7 @@ docs.toggleSubscript = function () {
el.dispatchEvent(ctrlPress);
}
- if (actionPluginPlatform !== "userscript") {
+ if (docs.platform !== "userscript") {
docs.runWithCreateKeyboard(_doToggleSubscript.toString(), "_doToggleSubscript", "");
return;
} else {
@@ -268,4 +269,4 @@ docs.getUserCursor = function () {
console.log("Couldn't locate the cursor!");
return $(".kix-cursor").first();
-}; \ No newline at end of file
+};
diff --git a/utils.js b/utils.js
index b46d05e..9372b71 100644
--- a/utils.js
+++ b/utils.js
@@ -1,6 +1,13 @@
-var utils = {};
+var docs = docs || {
+ id: window.location.href.split("/document/d/")[1].split("/")[0],
+ get name() {
+ return $(".docs-title-input-label-inner").text().trim();
+ },
+ platform: "chrome" //chrome, firefox, userscript
+};
+docs.utils = {};
-utils.observe = function (el, config, callback, observeOnce) {
+docs.utils.observe = function (el, config, callback, observeOnce) {
observeOnce = (typeof observeOnce !== "undefined") && observeOnce;
var observer = new MutationObserver(function(mutations) {
@@ -20,6 +27,7 @@ utils.stopEvent = function (e) {
utils.recipe(e, ["preventDefault", "stopPropagation"]);
};
+
utils.keyFromKeyCode = function (shifted, keyCode) {
var specialKeys = { 191: "/", 27: "Escape", 16: "Shift", 17: "Control", 18: "Alt", 8: "Backspace", 32: " ", 13: "Enter", 9: "Tab", 37: "ArrowLeft", 38: "ArrowUp", 39: "ArrowRight", 40: "ArrowDown" };
var shiftedSpecialKeys = { 191: "?" };
@@ -40,7 +48,7 @@ utils.keyFromKeyCode = function (shifted, keyCode) {
return shifts[c];
}
}
-}
+};
utils.createKeyboardEvent = function (type, info) {
var e = new KeyboardEvent(type, info);
@@ -71,4 +79,15 @@ utils.runInPage = function (script) {
return;
}
window.location = "javascript:" + script;
-}; \ No newline at end of file
+};
+
+//Thanks! https://stackoverflow.com/questions/1740700/how-to-get-hex-color-value-rather-than-rgb-value
+utils.rgb2hex = function(rgb) {
+ if (/^#[0-9A-F]{6}$/i.test(rgb)) return rgb;
+
+ rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
+ function hex(x) {
+ return ("0" + parseInt(x).toString(16)).slice(-2);
+ }
+ return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback