Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bijij committed Jul 17, 2023
1 parent a67784f commit 4cb6763
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"SwitchCase": 1
}
],
"linebreak-style": [
"error",
"unix"
],
"linebreak-style": "off",
"quotes": [
"error",
"single"
Expand Down
10 changes: 0 additions & 10 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,5 @@

</body>
<script src="/../js/localise.js"></script>
<script>
var data = document.querySelectorAll('[data-localise]');

for (var i = 0; i < data.length; i++) {
var obj = data[i];
var tag = obj.getAttribute('data-localise').toString();

localiseObject(obj, tag);
}
</script>

</html>
6 changes: 5 additions & 1 deletion js/background.base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use-strict';

import { toI18n } from './localise.js';
export function toI18n(str) {
return str.replace(/__MSG_(\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : '';
});
}

// Default options
const defaultOptions = {
Expand Down
13 changes: 11 additions & 2 deletions js/localise.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
'use-strict';

export function toI18n(str) {
function toI18n(str) {
return str.replace(/__MSG_(\w+)__/g, function (match, v1) {
return v1 ? chrome.i18n.getMessage(v1) : '';
});
}

export function localiseObject(obj, tag) {
function localiseObject(obj, tag) {
var msg = toI18n(tag);
if (msg != tag) obj.innerHTML = msg;
}

var data = document.querySelectorAll('[data-localise]');

for (var i = 0; i < data.length; i++) {
var obj = data[i];
var tag = obj.getAttribute('data-localise').toString();

localiseObject(obj, tag);
}

0 comments on commit 4cb6763

Please sign in to comment.