diff --git a/LICENSE b/LICENSE
index 2fe9495..4cacbb3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2013 Izzy Kulbe
+Copyright (c) 2022 izzy
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
diff --git a/README.md b/README.md
index 2d49b49..e6eea26 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,17 @@
-d3coder
-=============================
+# d3coder
-Google Chrome Encoding/Decoding Plugin for various types of encoding like
-base64, rot13 or unix timestamp conversion.
\ No newline at end of file
+Google Chrome encoding/decoding plugin for various types of encoding like
+base64, rot13 or unix timestamp conversion.
+## Changelog
+
+The full changelog can be found in [CHANGELOG.md](CHANGELOG.md)
+
+## Contributing
+
+Before contributing please make sure you have understood the [Code of Conduct](CODE_OF_CONDUCT.md).
+
+Please be aware that the code itself is undergoing a major rewrite at the
+moment to accomodate changes needed for the [extension manifest v3](https://developer.chrome.com/docs/extensions/mv3/intro/).
+
+If you have any questions feel free to drop me a DM at any of my socials or in
+my [Discord](https://discord.gg/yRTM7H2tek).
\ No newline at end of file
diff --git a/html/menu_ui.html b/html/menu_ui.html
index e35480f..b91cda1 100644
--- a/html/menu_ui.html
+++ b/html/menu_ui.html
@@ -146,7 +146,7 @@
__MSG_activate_functions__
Credits
-
This extension was developed by Izzy Kulbe <github@unikorn.me>
+
This extension was developed by izzy <github@unikorn.me>
Special thanks for several functions to the php.js team, they did a great job on porting some of the most important functions to JS.
diff --git a/js/D3.js b/js/D3.js
index 6105540..eccb3a5 100644
--- a/js/D3.js
+++ b/js/D3.js
@@ -1,65 +1,71 @@
-/**
- * Some functions from php.js (see phpjs.org)
- *
- * @version 4.1.0
- * @author Izzy Kulbe
- * @copyright (c) 2010 - 2019 Izzy Kulbe
+/**
+ * @returns Object containing the current tab
*/
+async function getCurrentTab() {
+ let queryOptions = {
+ active: true,
+ currentWindow: true
+ };
+ let [tab] = await chrome.tabs.query(queryOptions);
+ return tab;
+}
/**
* KEY FUNCTION NAMESPACE
*/
-var D3 =
-{
+var D3 = {
//needs a new Icon - best would be an icon per decoding type
//icon: "popupIcon.png",
icon: "../images/icon128.png",
/**
- * Version number
- *
- * @var String
- */
- version: "4.7.0",
-
- translations: {},
-
- /**
- * list all functions so we can use this while saving
- * @var Array
- */
- checkboxes: Array( "functions_rot13",
- "functions_timestamp",
- "functions_crc32",
- "functions_bin2hex",
- "functions_bin2txt",
- "functions_txt2hex",
- "functions_hex2txt",
- "functions_html_entity_decode",
- "functions_htmlentities",
- "functions_htmlspecialchars",
- "functions_htmlspecialchars_decode",
- "functions_uri_encode",
- "functions_uri_decode",
- "functions_md5",
- "functions_sha1",
- "functions_quoted_printable_decode",
- "functions_quoted_printable_encode",
- "functions_escapeshellarg",
- "functions_base64_encode",
- "functions_base64_decode",
- "functions_unserialize",
- "functions_leet_decode",
- "functions_leet_encode",
- "functions_reverse"),
-
- menuIds: {},
-
- lastMessage: '',
-
-
-
- checkInstall: function(callback) {
- chrome.storage.sync.get(null, function(items) {
+ * Version number
+ *
+ * @var String
+ */
+ version: "5.0.0",
+
+ /**
+ * Tabs that already had the content worker script injected
+ *
+ * @var Array
+ */
+ injected_tabs: incjected_tabs = [],
+
+ /**
+ * list all functions so we can use this while saving
+ * @var Array
+ */
+ checkboxes: Array("functions_rot13",
+ "functions_timestamp",
+ "functions_crc32",
+ "functions_bin2hex",
+ "functions_bin2txt",
+ "functions_txt2hex",
+ "functions_hex2txt",
+ "functions_html_entity_decode",
+ "functions_htmlentities",
+ "functions_htmlspecialchars",
+ "functions_htmlspecialchars_decode",
+ "functions_uri_encode",
+ "functions_uri_decode",
+ "functions_md5",
+ "functions_sha1",
+ "functions_quoted_printable_decode",
+ "functions_quoted_printable_encode",
+ "functions_escapeshellarg",
+ "functions_base64_encode",
+ "functions_base64_decode",
+ "functions_unserialize",
+ "functions_leet_decode",
+ "functions_leet_encode",
+ "functions_reverse"),
+
+ menuIds: {},
+
+ lastMessage: '',
+
+ checkInstall: function (callback) {
+ chrome.storage.sync.get(null, function (items) {
console.log("Check Install: Start");
update = {};
if (!items["messageType"]) {
@@ -78,202 +84,182 @@ var D3 =
update["checkboxes"][name] = true;
}
}
-
+
if (!items["version"]) {
update["version"] = D3.version;
}
- chrome.storage.sync.set(update, function(){
+ chrome.storage.sync.set(update, function () {
console.log("Installed decoder version " + D3.version);
});
- });
- },
-
- createPopup: function(title, text, type, clipboardCopy, tabId)
- {
- if(clipboardCopy) {
+ });
+ },
+
+ createPopup: async (title, text, type, clipboardCopy, tabId) => {
+ if (clipboardCopy) {
D3.copyToClipboard(text);
}
-
- D3.lastMessage = text;
-
+
+ D3.lastMessage = text;
+
+ // Inject the content scripts once at the start
+ if (!(tabId in D3.injected_tabs)) {
+ await chrome.scripting.insertCSS({
+ target: {
+ tabId: tabId
+ },
+ files: ["styles/content.css"]
+ });
+ await chrome.scripting.executeScript({
+ target: {
+ tabId: tabId
+ },
+ files: ['js/contentWorker.js']
+ });
+ D3.injected_tabs.push(tabId);
+ }
+
switch (type) {
case 'console':
- chrome.scripting.executeScript({target: {tabId: tabId}, files: ['js/contentWorker.js']});
-
- let inject_console = function(title, text) {
- console.log('d3coder:: FUNCTION:' + title)
- console.log('d3coder:: VALUE:', text);
+ let inject_console = function (title, text) {
+ console.log(['d3coder:: FUNCTION:' + title, text]);
};
- chrome.scripting.executeScript({target: {tabId: tabId}, func: inject_console, args: [title, text]});
-
+ chrome.scripting.executeScript({
+ target: {
+ tabId: tabId
+ },
+ func: inject_console,
+ args: [title, text]
+ });
+
break;
- case 'alert':
- let inject_alert = function(title, text) {
+ case 'alert':
+ let inject_alert = function (title, text) {
alert(title + '\n\n' + text);
};
- chrome.scripting.executeScript({target: {tabId: tabId}, func: inject_alert, args: [title, text]});
+ chrome.scripting.executeScript({
+ target: {
+ tabId: tabId
+ },
+ func: inject_alert,
+ args: [title, text]
+ });
break;
case 'div':
- chrome.scripting.insertCSS({target: {tabId: tabId}, files: ["styles/content.css"]});
- chrome.scripting.executeScript({target: {tabId: tabId}, files: ['js/contentWorker.js']});
-
- text = D3.base64_encode(text);
- let inject_div = function(title, text) {
+ let inject_div = function (title, text) {
D3content.createDiv(title, text);
};
- chrome.scripting.executeScript({target: {tabId: tabId}, func: inject_div, args: [title, text]});
+ chrome.scripting.executeScript({
+ target: {
+ tabId: tabId
+ },
+ func: inject_div,
+ args: [title, text]
+ });
break;
default:
- case 'inplace':
- chrome.scripting.executeScript({target: {tabId: tabId}, files: ['js/contentWorker.js']});
-
- text = D3.base64_encode(text);
- let inject_inplace = function(text) {
+ case 'inplace':
+ let inject_inplace = function (text) {
D3content.replaceText(text);
};
- chrome.scripting.executeScript({target: {tabId: tabId}, func: inject_inplace, args: [text]});
-
- break;
- }
- },
- copyToClipboard: function(text, fromClipboard=false) {
- async function getCurrentTab() {
- let queryOptions = {active: true, currentWindow: true};
- let [tab] = await chrome.tabs.query(queryOptions);
- return tab;
- }
+ chrome.scripting.executeScript({
+ target: {
+ tabId: tabId
+ },
+ func: inject_inplace,
+ args: [text]
+ });
- function copyToClipboard_inject (text) {
- let input = document.createElement('textarea');
- document.body.appendChild(input);
- input.value = text;
- input.focus();
- input.select();
- document.execCommand("copy");
- input.remove();
+ break;
}
-
- if (fromClipboard === true) {
- function pasteFromClipboard_inject () {
- let input = document.createElement('textarea');
- document.body.appendChild(input);
- input.focus();
- input.select();
- document.execCommand("paste");
- copyToClipboard_inject(D3lib[fn_name](clipboardText));
- }
-
- getCurrentTab().then(function (tab) {
- chrome.scripting.executeScript({
- target: {tabId: tab.id},
- func: pasteFromClipboard_inject
+ },
+ copyToClipboard: function (text) {
+ function copyToClipboard(text) {
+ if (navigator.clipboard) {
+ navigator.clipboard.writeText(text).then(function () {
+ console.log('D3: Copied to clipboard');
+ }, function (err) {
+ console.error(['D3: Error writing to clipboard', err]);
});
- });
+ } else {
+ console.error('D3: Clipboard not accessible');
+ }
}
getCurrentTab().then(function (tab) {
chrome.scripting.executeScript({
- target: {tabId: tab.id},
- func: copyToClipboard_inject,
- args: [text]}
- );
+ target: {
+ tabId: tab.id
+ },
+ func: copyToClipboard,
+ args: [text]
+ });
});
- return true;
},
-
- menus: false,
-
- menuLoadTime: 1000,
-
- createContextMenu: function() {
- D3.menus = true;
-
- var function_list = {
- 'functions_rot13': ['function_rot13', "rot13decode"],
- 'functions_timestamp': ['function_timestamp', "timestampToDate"],
- 'functions_bin2hex': ['function_bin2hex', "bin2hex"],
- 'functions_bin2txt': ['function_bin2txt', "bin2txt"],
- 'functions_txt2hex': ['function_ascii2hex', "txt2hex"],
- 'functions_hex2txt': ['function_hex2ascii', "hex2txt"],
- 'functions_uri_encode': ['function_uri_encode', "uri_encode"],
- 'functions_uri_decode': ['function_uri_decode', "uri_decode"],
- 'functions_htmlentities': ['function_html_entities', "htmlentities"],
- 'functions_html_entity_decode': ['function_html_entity_decode', "html_entity_decode"],
- 'functions_htmlspecialchars': ['function_htmlspecialchars', "htmlspecialchars"],
+
+ createContextMenu: function () {
+ const function_list = {
+ 'functions_rot13': ['function_rot13', "rot13decode"],
+ 'functions_timestamp': ['function_timestamp', "timestampToDate"],
+ 'functions_bin2hex': ['function_bin2hex', "bin2hex"],
+ 'functions_bin2txt': ['function_bin2txt', "bin2txt"],
+ 'functions_txt2hex': ['function_ascii2hex', "txt2hex"],
+ 'functions_hex2txt': ['function_hex2ascii', "hex2txt"],
+ 'functions_uri_encode': ['function_uri_encode', "uri_encode"],
+ 'functions_uri_decode': ['function_uri_decode', "uri_decode"],
+ 'functions_htmlentities': ['function_html_entities', "htmlentities"],
+ 'functions_html_entity_decode': ['function_html_entity_decode', "html_entity_decode"],
+ 'functions_htmlspecialchars': ['function_htmlspecialchars', "htmlspecialchars"],
'functions_htmlspecialchars_decode': ['function_htmlspecialchars_decode', "htmlspecialchars_decode"],
- 'functions_md5': ['function_md5', "md5"],
- 'functions_sha1': ['function_sha1', "sha1"],
- 'functions_crc32': ['function_crc32', "crc32"],
+ 'functions_md5': ['function_md5', "md5"],
+ 'functions_sha1': ['function_sha1', "sha1"],
+ 'functions_crc32': ['function_crc32', "crc32"],
'functions_quoted_printable_decode': ['function_quoted_printable_decode', "quoted_printable_decode"],
'functions_quoted_printable_encode': ['function_quoted_printable_encode', "quoted_printable_encode"],
- 'functions_escapeshellarg': ['function_escapeshellarg', "escapeshellarg"],
- 'functions_base64_encode': ['function_base64_encode', "base64_encode"],
- 'functions_base64_decode': ['function_base64_decode', "base64_decode"],
- 'functions_unserialize': ['function_unserialize', "unserialize"],
- 'functions_leet_encode': ['function_leet_encode', "leetEncode"],
- 'functions_leet_decode': ['function_leet_decode', "leetDecode"],
- 'functions_reverse': ['function_reverse_text', "reverseText"],
+ 'functions_escapeshellarg': ['function_escapeshellarg', "escapeshellarg"],
+ 'functions_base64_encode': ['function_base64_encode', "base64_encode"],
+ 'functions_base64_decode': ['function_base64_decode', "base64_decode"],
+ 'functions_unserialize': ['function_unserialize', "unserialize"],
+ 'functions_leet_encode': ['function_leet_encode', "leetEncode"],
+ 'functions_leet_decode': ['function_leet_decode', "leetDecode"],
+ 'functions_reverse': ['function_reverse_text', "reverseText"],
};
function clearMenu() {
- //while (localStorage.getItem("clearmenumutex") === "1") { }
-
- console.log("Menu: Clearing old menus");
- //localStorage.setItem("clearmenumutex", "1");
+ console.log(D3.menuIds);
for (id in D3.menuIds) {
- console.log("Menu: Removing menu entry: " + D3.menuIds[id]);
- console.log("Menu: Menu ID: " + id);
if (id && D3.menuIds[id] != null) {
chrome.contextMenus.remove(D3.menuIds[id]);
}
D3.menuIds[id] = null;
}
- //localStorage.setItem("clearmenumutex", "0");
+ console.log(D3.menuIds);
}
function createMenu(items, name) {
- let menu = null, changed = false;
- console.log("Menu: " + name);
+ let menu = null;
+
if (items.checkboxes[name] == true && !D3.menuIds[name]) {
- console.log("Menu: Creating " + name);
-
// Menu for selected text
menu = {
- "title" : D3.translate(function_list[name][0]),
- "contexts" : ["selection", "editable"],
+ "title": D3.translate(function_list[name][0]),
+ "contexts": ["selection", "editable"],
"id": "d3coder-selection-" + function_list[name][1]
};
- D3.menuIds[name]=chrome.contextMenus.create(menu);
-
- // Menu for normal page
- menu = {
- "title" : D3.translate(function_list[name][0]),
- "contexts" : ["page"],
- "id": "d3coder-" + function_list[name][1]
- };
- D3.menuIds[name + '_c']=chrome.contextMenus.create(menu);
-
- changed = true;
+ D3.menuIds[name] = chrome.contextMenus.create(menu);
} else if (items.checkboxes[name] == false) {
if (D3.menuIds[name]) {
- console.log("Menu: Removing " + D3.menuIds[name]);
+ // console.log("Menu: Removing " + D3.menuIds[name]);
chrome.contextMenus.remove(D3.menuIds[name]);
D3.menuIds[name] = null;
}
-
- if (D3.menuIds[name + '_c']) {
- console.log("Menu: Removing " + D3.menuIds[name + '_c']);
- chrome.contextMenus.remove(D3.menuIds[name + '_c']);
- D3.menuIds[name + '_c'] = null;
- }
- }
+ }
}
chrome.storage.sync.get(null, function (items) {
@@ -282,31 +268,23 @@ var D3 =
for (itemName in items.checkboxes) {
createMenu(items, itemName);
}
-
+
if (!D3.menuIds["options"]) {
// Menu item for options
menu = {
- "title" : D3.translate("extName") + " " + D3.translate("settings"),
- "contexts" : ["all"],
+ "title": D3.translate("extName") + " " + D3.translate("settings"),
+ "contexts": ["all"],
"id": "d3coder-settings"
}
-
- D3.menuIds["options"]=chrome.contextMenus.create(menu);
+
+ D3.menuIds["options"] = chrome.contextMenus.create(menu);
}
- console.log(D3.menuIds);
});
- },
-
- translate: function(name) {
- if ("getMessage" in chrome.i18n) {
- return chrome.i18n.getMessage(name);
- } else {
- // TODO: Fill translations table from the content page
- if (name in D3.translations) {
- return D3.translations[name];
- } else {
- return "Could not translate " + name;
- }
- }
+ },
+
+ translate: function (name) {
+ let e_msg = "Could not translate " + name;
+
+ return chrome.i18n.getMessage(name) || e_msg;
}
-};
+};
\ No newline at end of file
diff --git a/js/D3lib.js b/js/D3lib.js
index 3a5468b..6c552a5 100644
--- a/js/D3lib.js
+++ b/js/D3lib.js
@@ -54,6 +54,7 @@ var D3lib = {
dateObject.setTime(timestamp * 1000);
return dateObject;
},
+
crc32: function (str) {
str = D3lib.utf8_encode(str);
const table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
@@ -71,6 +72,7 @@ var D3lib = {
return "0x" + (crc ^ (-1)).toString(16);
},
+
bin2hex: function (s) {
var i, f = 0,
a = [];
@@ -84,6 +86,7 @@ var D3lib = {
return a.join('');
},
+
bin2txt: function (binary) {
binary = binary.replace(/(\s)/gm, "");
@@ -104,6 +107,7 @@ var D3lib = {
return string;
},
+
txt2hex: function (text) {
var arr = [];
for (var i = 0, l = text.length; i < l; i++) {
@@ -112,6 +116,7 @@ var D3lib = {
}
return arr.join('');
},
+
hex2txt: function (data) {
data = data.toString(); // Force conversion
data = data.replace(/[^0-9a-fA-F]+/g, ""); // Strip all non-HEX characters
@@ -120,6 +125,7 @@ var D3lib = {
str += String.fromCharCode(parseInt(data.substr(i, 2), 16));
return str;
},
+
html_entity_decode: function (string, quote_style) {
var hash_map = {},
symbol = '',
@@ -144,6 +150,7 @@ var D3lib = {
return tmp_str;
},
+
htmlentities: function (string, quote_style) {
var hash_map = {},
symbol = '',
@@ -162,6 +169,7 @@ var D3lib = {
return tmp_str;
},
+
htmlspecialchars: function (string, quote_style, charset, double_encode) {
var optTemp = 0,
i = 0,
@@ -207,6 +215,7 @@ var D3lib = {
return string;
},
+
htmlspecialchars_decode: function (string, quote_style) {
var optTemp = 0,
i = 0,
@@ -250,12 +259,15 @@ var D3lib = {
return string;
},
+
uri_encode: function (str) {
return encodeURIComponent(str);
},
+
uri_decode: function (str) {
return decodeURIComponent(str);
},
+
md5: function (str) {
var xl;
@@ -458,6 +470,7 @@ var D3lib = {
return temp.toLowerCase();
},
+
sha1: function (str) {
var rotate_left = function (n, s) {
var t4 = (n << s) | (n >>> (32 - s));
@@ -582,17 +595,17 @@ var D3lib = {
temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toLowerCase();
},
+
quoted_printable_decode: function (str) {
- var RFC2045Decode1 = /=\r\n/gm,
- // Decodes all equal signs followed by two hex digits
- RFC2045Decode2IN = /=([0-9A-F]{2})/gim, // the RFC states against decoding lower case encodings, but following apparent PHP behavior
- // RFC2045Decode2IN = /=([0-9A-F]{2})/gm,
+ const RFC2045Decode1 = /=\r\n/gm;
+ const RFC2045Decode2IN = /=([0-9A-F]{2})/gim;
+ const RFC2045Decode2OUT = function (sMatch, sHex) {
+ return String.fromCharCode(parseInt(sHex, 16));
+ }
- RFC2045Decode2OUT = function (sMatch, sHex) {
- return String.fromCharCode(parseInt(sHex, 16));
- };
- return str.replace(RFC2045Decode1, '').replace(RFC2045Decode2IN, RFC2045Decode2OUT);
+ return D3.utf8_decode(str.replace(RFC2045Decode1, '').replace(RFC2045Decode2IN, RFC2045Decode2OUT));
},
+
quoted_printable_encode: function (str) {
var hexChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'],
RFC2045Encode1IN = / \r\n|\r\n|[^!-<>-~ ]/gm,
@@ -616,6 +629,7 @@ var D3lib = {
str = str.replace(RFC2045Encode1IN, RFC2045Encode1OUT).replace(RFC2045Encode2IN, RFC2045Encode2OUT);
return str.substr(0, str.length - 3);
},
+
escapeshellarg: function (arg) {
var ret = '';
@@ -625,6 +639,7 @@ var D3lib = {
return "'" + ret + "'";
},
+
leetEncode: function (inputString) {
if (!inputString) return "";
@@ -641,6 +656,7 @@ var D3lib = {
);
return inputString;
},
+
leetDecode: function (inputString) {
for (i = 0; i < D3lib.LettersLeet.length; ++i)
inputString = inputString.replace(
@@ -655,9 +671,11 @@ var D3lib = {
);
return inputString;
},
+
reverseText: function (inputString) {
return inputString.split("").reverse().join("");
},
+
base64_encode: function (data) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
@@ -700,6 +718,7 @@ var D3lib = {
return enc;
},
+
base64_decode: function (data) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
@@ -739,6 +758,7 @@ var D3lib = {
return dec;
},
+
get_html_translation_table: function (table, quote_style) {
var entities = {},
@@ -883,6 +903,7 @@ var D3lib = {
return hash_map;
},
+
unserialize: function (data) {
data = data + '';
@@ -1279,15 +1300,16 @@ var D3lib = {
return utftext;
},
+
utf8_decode: function (str_data) {
- var tmp_arr = [],
- i = 0,
- ac = 0,
- c1 = 0,
- c2 = 0,
- c3 = 0;
+ let tmp_arr = [];
+ let i = 0;
+ let ac = 0;
+ let c1 = 0;
+ let c2 = 0;
+ let c3 = 0;
- str_data += '';
+ str_data = str_data + '';
while (i < str_data.length) {
c1 = str_data.charCodeAt(i);
@@ -1327,11 +1349,10 @@ var D3lib = {
return "[WARNING: Too much recursion]\n";
}
- var
- i,
- r = '',
- t = typeof x,
- tab = '';
+ let i;
+ let r = '';
+ let t = typeof x;
+ let tab = '';
if (x === null) {
r += "(null)\n";
diff --git a/js/contentWorker.js b/js/contentWorker.js
index 58b460d..c693d06 100644
--- a/js/contentWorker.js
+++ b/js/contentWorker.js
@@ -1,39 +1,30 @@
+console.log("d3coder: Loaded contentWorker.js");
+
/**
- * @version 4.0.0
- * @author Izzy Kulbe
- * @copyright (c) 2010 - 2018 Izzy Kulbe
+ * @version 5.0.0
*/
D3content = {
createDiv: function(title, text)
{
- text = D3content.base64_decode(text);
- var hr = document.createElement('hr'),
- infoDiv,
- infoText,
- infoHeading,
- infoClipboardCopy,
- backUrl,
- resizeHandle,
- heading,
- closeElem,
- centerBottomResize,
- startX,
- startY,
- startWidth,
- startHeight;
+ let hr = document.createElement('hr');
+ let infoDiv;
+ let infoText;
+ let infoHeading;
+ let resizeHandle;
+ let heading;
+ let closeElem;
+ let startY;
+ let startHeight;
if(!document.getElementById('D3-inject')) {
infoDiv = document.createElement('div');
infoDiv.id = 'D3-inject';
infoDiv.className = 'content';
- backUrl = chrome.extension.getURL("images/grip.png"),
-
resizeHandle = document.createElement('div');
resizeHandle.id = 'D3-inject_handle';
resizeHandle.className = 'handle vertical';
resizeHandle.style.backgroundColor = '#333';
- resizeHandle.style.backgroundImage = 'url(\'' + backUrl + '\')';
resizeHandle.style.backgroundRepeat = ' no-repeat;';
heading = document.createElement('h1');
@@ -93,7 +84,7 @@ D3content = {
infoDiv = document.getElementById('D3-inject');
}
- infoHeading = document.createElement('h3');
+ infoHeading = document.createElement('h2');
infoHeading.className = 'D3-inject-heading';
infoHeading.innerText = title;
@@ -101,37 +92,18 @@ D3content = {
infoText.className = 'D3-inject-text';
infoText.innerText = text;
- infoClipboardCopy = document.createElement('a');
- infoClipboardCopy.href = 'javascript:void';
- infoClipboardCopy.innerText = ' ';
- infoClipboardCopy.style.width = 20;
- infoClipboardCopy.style.height = 20;
- infoClipboardCopy.style.backgroundImage = 'url(data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5Ojf/2wBDAQoKCg0MDRoPDxo3JR8lNzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzf/wAARCAAUABQDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAQFBgf/xAAmEAABAwQCAQMFAAAAAAAAAAABAgMEAAUGERIhYRMiMQcjY5Gz/8QAFQEBAQAAAAAAAAAAAAAAAAAABAP/xAAcEQACAQUBAAAAAAAAAAAAAAAAAQIDERIx0SL/2gAMAwEAAhEDEQA/AOnZVerjbp1rg2lmOt+cp3an0qUEpQkKOgkgk6J/XmqGdkWR2aG5NdQy+y2pBeS/FcbI2dew70OyOjvXfZq1ydfHNsS8ql/zFQ/qOtQw24FSSPez8j8go8m8Zu+uIvFK8FbfTcUpSkEDPZNjMa9ORpD0yfHejKV6TkZ7gU8hpWjo/OhVCnBIkz7Uy83x9kkcmnZnJKu99jj4pSi1EsxNN+TeNN+kgJ5rX5WdmlKUoMf/2Q==)';
- infoClipboardCopy.style.position = 'absolute';
- infoClipboardCopy.style.top = 0;
- infoClipboardCopy.style.right = 0;
- infoClipboardCopy.title = chrome.i18n.getMessage('copy_last_conversion_to_clipboard');
- infoClipboardCopy.id = 'D3-clipboard-button';
-
hr = document.createElement('hr');
infoDiv.appendChild(infoHeading);
- infoDiv.appendChild(infoClipboardCopy);
infoDiv.appendChild(infoText);
infoDiv.appendChild(hr);
-
- document.getElementById('D3-clipboard-button').addEventListener('click', function(){
- chrome.extension.sendRequest({command: "doCopy"}, function(response) {
- console.log(response);
- });
- });
},
replaceText: function(text)
{
+ console.log("replaceText", text);
var selection, range;
- text = D3content.base64_decode(text);
if (window.getSelection) {
selection = window.getSelection();
if (selection.rangeCount) {
@@ -143,70 +115,5 @@ D3content = {
range = document.selection.createRange();
range.text = text;
}
- },
-
- logConsole: function(text)
- {
- console.log(text);
- },
- base64_decode: function (data) {
- var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
-
- if (!data) {
- return data;
- }
-
- data += '';
-
- do { // unpack four hexets into three octets using index points in b64
- h1 = b64.indexOf(data.charAt(i++));
- h2 = b64.indexOf(data.charAt(i++));
- h3 = b64.indexOf(data.charAt(i++));
- h4 = b64.indexOf(data.charAt(i++));
-
- bits = h1<<18 | h2<<12 | h3<<6 | h4;
-
- o1 = bits>>16 & 0xff;
- o2 = bits>>8 & 0xff;
- o3 = bits & 0xff;
-
- if (h3 == 64) {
- tmp_arr[ac++] = String.fromCharCode(o1);
- } else if (h4 == 64) {
- tmp_arr[ac++] = String.fromCharCode(o1, o2);
- } else {
- tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
- }
- } while (i < data.length);
-
- dec = tmp_arr.join('');
- dec = D3content.utf8_decode(dec);
-
- return dec;
- },
- utf8_decode: function ( str_data ) {
- var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
-
- str_data += '';
-
- while ( i < str_data.length ) {
- c1 = str_data.charCodeAt(i);
- if (c1 < 128) {
- tmp_arr[ac++] = String.fromCharCode(c1);
- i++;
- } else if ((c1 > 191) && (c1 < 224)) {
- c2 = str_data.charCodeAt(i+1);
- tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
- i += 2;
- } else {
- c2 = str_data.charCodeAt(i+1);
- c3 = str_data.charCodeAt(i+2);
- tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
- }
-
- return tmp_arr.join('');
}
-};
+};
\ No newline at end of file
diff --git a/js/background.js b/js/serviceworker.js
similarity index 57%
rename from js/background.js
rename to js/serviceworker.js
index 58c554c..f15f386 100644
--- a/js/background.js
+++ b/js/serviceworker.js
@@ -9,30 +9,27 @@ chrome.runtime.onInstalled.addListener(() => {
});
chrome.storage.onChanged.addListener((changes, namespace) => {
- D3.createContextMenu();
+ D3.createContextMenu();
});
chrome.runtime.onMessage.addListener(
(request, sender, sendResponse) => {
- console.log(sender.tab ?
- "from a content script:" + sender.tab.url :
- "from the extension");
+ console.log([request, sender, sendResponse]);
+
if (request.command == "doCopy") {
- console.log("chrome.runtime.onMessage", D3);
var responseStatus = D3.copyToClipboard(D3.lastMessage);
sendResponse({status: [chrome.i18n.getMessage("message_copied_to_clipboard"), responseStatus] });
} else if (request.command == "setContextMenuTitle") {
chrome.contextMenus.update(contextMenuId, {title: request.message});
} else {
- sendResponse({}); // snub them.
+ sendResponse({});
}
});
chrome.contextMenus.onClicked.addListener(
(info, tab) => {
- console.log("onClicked: ", info, tab);
-
menuId = info.menuItemId;
+
// Get just the name and a boolean for editable text
let fn_normalized = menuId.replace(/d3coder-(selection-|)/, "");
let fn_name = menuId.replace(/d3coder-(selection-|)function_/, "")
@@ -40,41 +37,20 @@ chrome.contextMenus.onClicked.addListener(
// Menu item for the extension's settings page
if (menuId === 'd3coder-settings') {
- console.log("Open d3coder settings");
- if ("openOptionsPage" in chrome.runtime) {
- chrome.runtime.openOptionsPage();
- } else {
- window.open(chrome.runtime.getURL('html/menu_ui.html'));
- }
-
+ chrome.runtime.openOptionsPage();
// Menu for selected/editable text
} else if (fn_selection === true && fn_normalized in D3lib) {
chrome.storage.sync.get(null, (items) => {
D3.createPopup(
- D3.translate(fn_normalized),
+ D3.translate(`function_${fn_normalized}`),
D3lib[fn_normalized](info.selectionText),
items["messageType"],
items["clipboardSave"],
tab.id
);
});
-
- // Nothing selected(get text from clipboard)
- } else if (fn_normalized in D3lib) {
- var bg = chrome.extension.getBackgroundPage(),
- clipboard = bg.document.getElementById("clipboard"),
- clipboardText;
-
- clipboard.style.display = "block";
- clipboard.select();
- bg.document.execCommand("Paste");
- clipboardText = clipboard.value;
- clipboard.style.display = "none";
-
- D3.copyToClipboard(D3lib[fn_name](clipboardText));
-
} else {
- console.log("Unknown function in onClicked: " + menuId)
+ console.error("Unknown function in onClicked: " + menuId)
}
}
);
\ No newline at end of file
diff --git a/manifest.json b/manifest.json
index c8e5297..79d1a68 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "__MSG_extName__",
- "version": "4.8.0",
+ "version": "5.0.0",
"description": "__MSG_extDescription__",
"options_ui": {
"page": "html/menu_ui.html",
@@ -10,30 +10,16 @@
"permissions": [
"contextMenus",
"clipboardWrite",
- "clipboardRead",
"storage",
"scripting",
"activeTab"
],
"background": {
- "service_worker": "js/background.js"
+ "service_worker": "js/serviceworker.js"
},
"icons": {
"16": "images/icon16.png",
"48": "images/icon48.png",
"128": "images/icon128.png" },
- "content_scripts": [
- {
- "matches": ["*://*/*"],
- "css": ["styles/content.css"],
- "js": ["js/contentWorker.js"],
- "all_frames": true
- }],
- "web_accessible_resources": [
- {
- "resources": ["images/grip.png"],
- "matches": ["*://*/*"]
- }
- ],
"default_locale": "en"
}
diff --git a/styles/content.css b/styles/content.css
index 7989c78..99c9dbe 100644
--- a/styles/content.css
+++ b/styles/content.css
@@ -1,47 +1,51 @@
-/**
- * @version 1.0
- * @author Izzy Kulbe
- * @copyright (c) 2010 - 2018 Izzy Kulbe
- */
-#D3-inject
-{
- z-index: 1000;
- position: fixed;
- width: 100%;
- height: 200px;
- bottom: 0;
- left: 0;
- background: lightgrey;
- border-top: 1px solid grey;
- overflow: auto;
- -webkit-box-shadow: 0px 0px 30px #000;
- text-align: left !important;
-}
-
-#D3-inject-close
-{
- z-index: 1100;
- float: right;
- margin-right: 30px;
- cursor: pointer;
-}
-
-#D3-inject-heading
-{
- font-size: 15px;
-}
-
-#D3-inject, #D3-inject-heading, #D3-inject-close, .D3-inject-heading
-{
- color: black !important;
+#D3-inject {
+ z-index: 1000;
+ position: fixed;
+ width: 100%;
+ height: 200px;
+ bottom: 0;
+ left: 0;
+ background: lightgrey;
+ border-top: 1px solid grey;
+ overflow: auto;
+ -webkit-box-shadow: 0px 0px 30px #000;
+ text-align: left !important;
+}
+
+#D3-inject-close {
+ z-index: 1100;
+ float: right;
+ margin-right: 30px;
+ cursor: pointer;
+}
+
+#D3-inject-heading {
+ font-size: 1rem;
+}
+
+.D3-inject-heading {
+ font-size: 1rem;
+}
+
+#D3-inject,
+#D3-inject-heading,
+#D3-inject-close,
+.D3-inject-heading {
+ color: black !important;
+ margin: 0;
+ padding: .5rem;
}
.D3-inject-text {
- word-wrap: break-word;
+ word-wrap: break-word;
+ background-color: #CCC;
+ border: 1px solid #999;
+ border-radius: 2px;
+ margin: .3rem .5rem .5rem;
}
div.handle {
- background: #333 ;
+ background: #333;
z-index: 2;
position: absolute;
}
@@ -52,10 +56,11 @@ div.handle.vertical {
cursor: row-resize;
z-index: 1;
background-position: center -19px;
- left: 0;
+ left: 0;
}
+
#D3-inject_handle {
bottom: 200px;
z-index: 1002;
position: fixed;
-}
+}
\ No newline at end of file