Skip to content

Commit

Permalink
Merge pull request #120 from izzy/bugfix/translation-error
Browse files Browse the repository at this point in the history
Bugfixes in inject div/translation output
  • Loading branch information
izzy authored Oct 22, 2022
2 parents d3757a2 + 8ac7da8 commit 5b51d95
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGELOG
=============================
* 5.1.1
* Fixed a bug where some translations would not be retrieved properly
* Fixed a bug where the Timestamp to Date function would sometimes return [object Object]
* 5.1.0
* Added browser polyfill in preparation for Firefox compatibility
* 5.0.2
Expand Down
58 changes: 29 additions & 29 deletions js/D3.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,34 @@ var D3 = {
});
},

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_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"],
};
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_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"],
},

createContextMenu: function () {
function clearMenu() {
for (id in D3.menuIds) {
if (id && D3.menuIds[id] != null) {
Expand All @@ -246,9 +246,9 @@ var D3 = {
if (items.checkboxes[name] == true && !D3.menuIds[name]) {
// Menu for selected text
menu = {
"title": D3.translate(function_list[name][0]),
"title": D3.translate(D3.function_list[name][0]),
"contexts": ["selection", "editable"],
"id": "d3coder-selection-" + function_list[name][1]
"id": "d3coder-selection-" + D3.function_list[name][1]
};
try {
D3.menuIds[name] = browser.contextMenus.create(menu);
Expand Down
2 changes: 1 addition & 1 deletion js/D3lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var D3lib = {

var dateObject = new Date();
dateObject.setTime(timestamp * 1000);
return dateObject;
return dateObject.toString();
},

crc32: function (str) {
Expand Down
18 changes: 12 additions & 6 deletions js/serviceworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@ browser.runtime.onMessage.addListener(

if (request.command == "doCopy") {
var responseStatus = D3.copyToClipboard(D3.lastMessage);
sendResponse({status: [browser.i18n.getMessage("message_copied_to_clipboard"), responseStatus] });
sendResponse({
status: [browser.i18n.getMessage("message_copied_to_clipboard"), responseStatus]
});
} else if (request.command == "setContextMenuTitle") {
browser.contextMenus.update(contextMenuId, {title: request.message});
browser.contextMenus.update(contextMenuId, {
title: request.message
});
} else {
sendResponse({});
}
});
});

browser.contextMenus.onClicked.addListener(
(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_/, "")

let fn_name = Object.entries(D3.function_list).find(fn => fn[1].includes(fn_normalized))[1][0];

let fn_selection = menuId.includes("-selection-");

// Menu item for the extension's settings page
if (menuId === 'd3coder-settings') {
browser.runtime.openOptionsPage();
// Menu for selected/editable text
// Menu for selected/editable text
} else if (fn_selection === true && fn_normalized in D3lib) {
browser.storage.sync.get(null).then((items) => {
D3.createPopup(
D3.translate(`function_${fn_normalized}`),
D3.translate(`${fn_name}`),
D3lib[fn_normalized](info.selectionText),
items["messageType"],
items["clipboardSave"],
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "__MSG_extName__",
"version": "5.1.0",
"version": "5.1.1",
"description": "__MSG_extDescription__",
"options_ui": {
"page": "html/menu_ui.html",
Expand Down

0 comments on commit 5b51d95

Please sign in to comment.