[gnome-browser-extension/wip/refactor: 5/7] Drop external libraries and use vanilla js




commit 15e45ef21ceee676614ded9a76224d05cd8bae6f
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Thu Aug 4 22:19:15 2022 +0400

    Drop external libraries and use vanilla js

 extension/css/dialog-polyfill.css             |    37 -
 extension/css/options.css                     |    16 +-
 extension/css/tabby.min.css                   |     2 -
 extension/include/compat-common.js            |    27 +
 extension/include/external/dialog-polyfill.js |   766 --
 extension/include/external/jquery-3.6.0.js    | 10881 ------------------------
 extension/include/external/tabby-10.1.0.js    |   383 -
 extension/include/i18n.js                     |    58 +-
 extension/include/notifications.js            |     8 +-
 extension/include/sync.js                     |    90 +-
 extension/include/toolbar.js                  |     4 +-
 extension/include/update.js                   |     8 +-
 extension/manifest.json                       |     1 -
 extension/options.html                        |    15 +-
 extension/options.js                          |   162 +-
 15 files changed, 206 insertions(+), 12252 deletions(-)
---
diff --git a/extension/css/options.css b/extension/css/options.css
index 89b1bbb..3c7ba6e 100644
--- a/extension/css/options.css
+++ b/extension/css/options.css
@@ -6,17 +6,29 @@ body {
 
 #update_check_period { width: 5em; }
 #status {
-       display: none;
+       visibility: hidden;
+       opacity: 0;
        color: green;
        text-align: center;
 }
 
 #error {
-       display: none;
+       visibility: hidden;
+       opacity: 0;
        color: red;
        text-align: center;
 }
 
+.show {
+       visibility: visible !important;
+       opacity: 1 !important;
+       transition: visibility 0.25s, opacity 0.25s ease-in-out;
+}
+
+.hide {
+       display: none;
+}
+
 .buttons { text-align: center; margin-top: 1em; }
 .notice { font-size: 90%; font-weight: normal; margin-top: 0.5em; white-space: nowrap; }
 .update-notice { display: none; }
diff --git a/extension/include/compat-common.js b/extension/include/compat-common.js
index f32923c..bd60d06 100644
--- a/extension/include/compat-common.js
+++ b/extension/include/compat-common.js
@@ -10,6 +10,33 @@
 
 /* global chrome, COMPAT */
 
+$ = (...args) => document.querySelector(...args);
+$$ = (...args) => document.querySelectorAll(...args);
+
+function empty(element) {
+       while(element.firstChild) element.removeChild(element.firstChild);
+}
+
+function isEmptyObject(object) {
+       for (const k in object) return false;
+       return true;
+}
+
+function showWithDelay(element, delay, message) {
+       if (message) {
+               element.innerHtml = message;
+       }
+
+       element.classList.remove('hide');
+       element.classList.add('show');
+       setTimeout(() => {
+               element.classList.remove('show');
+               setTimeout(() => {
+                       element.classList.add('hide');
+               }, 250);
+       }, delay);
+}
+
 COMPAT.PERMISSIONS_CONTAINS            = true;
 COMPAT.PERMISSIONS_EVENTS              = true;
 COMPAT.SYNC_STORAGE                            = true;
diff --git a/extension/include/i18n.js b/extension/include/i18n.js
index 56b8726..ba9ac4a 100644
--- a/extension/include/i18n.js
+++ b/extension/include/i18n.js
@@ -1,42 +1,32 @@
-/*
-    GNOME Shell integration for Chrome
-    Copyright (C) 2016  Yuri Konotopov <ykonotopov gnome org>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
- */
+// # SPDX-License-Identifer: GPL-3.0-or-later
 
 m = chrome.i18n.getMessage;
-i18n = (function($) {
-       return function() {
-               $('[data-i18n]').each(function () {
-                       var data = $.map($(this).data('i18n').split(','), function(value) {
-                               value = value.trim();
+i18n = (() => {
+       $$('[data-i18n]').forEach((element) => {
+               let data = element.dataset.i18n.split(',').map((value) => {
+                       value = value.trim();
 
-                               if(value.startsWith('__MSG_'))
+                       if(value.startsWith('__MSG_'))
+                       {
+                               return value.replace(/__MSG_(\w+)__/g, function(match, key)
                                {
-                                       return value.replace(/__MSG_(\w+)__/g, function(match, key)
-                                       {
-                                           return key ? m(key) : "";
-                                       });
-                               }
+                                       return key ? m(key) : "";
+                               });
+                       }
 
-                               return value;
-                       });
+                       return value;
+               });
 
-                       if(data.length)
+               if(data)
+               {
+                       if(element.dataset.i18nHtml)
                        {
-                               if($(this).data('i18n-html'))
-                               {
-                                       $(this).html(m(data[0], data.slice(1)));
-                               }
-                               else
-                               {
-                                       $(this).text(m(data[0], data.slice(1)));
-                               }
+                               element.innerHtml = m(data[0], data.slice(1));
                        }
-               });
-       }
-})(jQuery);
+                       else
+                       {
+                               element.innerText = m(data[0], data.slice(1));
+                       }
+               }
+       });
+});
diff --git a/extension/include/notifications.js b/extension/include/notifications.js
index 0efb69e..ddfaa0c 100644
--- a/extension/include/notifications.js
+++ b/extension/include/notifications.js
@@ -8,7 +8,7 @@
     (at your option) any later version.
  */
 
-GSC.notifications = (function($) {
+GSC.notifications = (function() {
        var DEFAULT_NOTIFICATION_OPTIONS = {
                type: chrome.notifications.TemplateType.BASIC,
                iconUrl: 'icons/GnomeLogo-128.png',
@@ -80,7 +80,7 @@ GSC.notifications = (function($) {
                        }, function (items) {
                                var notifications = items.notifications;
 
-                               notifications[name] = $.extend(DEFAULT_NOTIFICATION_OPTIONS, options);
+                               notifications[name] = {...DEFAULT_NOTIFICATION_OPTIONS, ...options};
 
                                _create(name, notifications[name], function (notificationId) {
                                        chrome.storage.local.set({
@@ -165,7 +165,7 @@ GSC.notifications = (function($) {
                        window.postMessage({
                                execute: 'createNotification',
                                name: name,
-                               options: $.extend(DEFAULT_NOTIFICATION_OPTIONS, options)
+                               options: {...DEFAULT_NOTIFICATION_OPTIONS, ...options}
                        }, "*");
                }
 
@@ -215,4 +215,4 @@ GSC.notifications = (function($) {
                        });
                }
        };
-})(jQuery);
+})();
diff --git a/extension/include/sync.js b/extension/include/sync.js
index 9d20427..23e8b4e 100644
--- a/extension/include/sync.js
+++ b/extension/include/sync.js
@@ -34,12 +34,12 @@ GSC.sync = (function($) {
                                enabled = false;
 
                                // Remove all disabled extensions from queue
-                               $.each(extensionChangedQueue, function(extensionId, extension) {
+                               for (const [extensionId, extension] of Object.entries(extensionChangedQueue)) 
{
                                        if(extension.state == EXTENSION_STATE.DISABLED)
                                        {
                                                delete extensionChangedQueue[extensionId];
                                        }
-                               });
+                               };
                        }
                        else if (state === 'active')
                        {
@@ -146,38 +146,39 @@ GSC.sync = (function($) {
         *      ...
         * ]
         */
-       function getExtensions(deferred, remoteExtensions) {
-               GSC.sendNativeRequest({
-                       execute: 'listExtensions'
-               }, function(response) {
-                       if(response && response.success)
-                       {
-                               if(remoteExtensions)
+       function getExtensions(remoteExtensions) {
+               return new Promise((resolve, reject) => {
+                       GSC.sendNativeRequest({
+                               execute: 'listExtensions'
+                       }, function(response) {
+                               if(response && response.success)
                                {
-                                       deferred.resolve(mergeExtensions(remoteExtensions, 
response.extensions));
+                                       if(remoteExtensions)
+                                       {
+                                               resolve(mergeExtensions(remoteExtensions, 
response.extensions));
+                                       }
+                                       else
+                                       {
+                                               chrome.storage.sync.get({
+                                                       extensions: {}
+                                               }, function(options) {
+                                                       if(chrome.runtime.lastError)
+                                                       {
+                                                               reject(chrome.runtime.lastError.message);
+                                                       }
+                                                       else
+                                                       {
+                                                               resolve(mergeExtensions(options.extensions, 
response.extensions));
+                                                       }
+                                               });
+                                       }
                                }
                                else
                                {
-                                       chrome.storage.sync.get({
-                                               extensions: {}
-                                       }, function(options) {
-                                               if(chrome.runtime.lastError)
-                                               {
-                                                       deferred.reject(chrome.runtime.lastError.message);
-                                               }
-                                               else
-                                               {
-                                                       var extensions = mergeExtensions(options.extensions, 
response.extensions);
-                                                       deferred.resolve(extensions);
-                                               }
-                                       });
+                                       var message = response && response.message ? response.message : 
m('error_connector_response');
+                                       reject(message);
                                }
-                       }
-                       else
-                       {
-                               var message = response && response.message ? response.message : 
m('error_connector_response');
-                               deferred.reject(message);
-                       }
+                       });
                });
        }
 
@@ -199,7 +200,7 @@ GSC.sync = (function($) {
        {
                var extensions = {};
 
-               $.each(remoteExtensions, function(key, extension) {
+               for (const [key, extension] of Object.entries(remoteExtensions)) {
                        if(extension.uuid && extension.name && extension.state)
                        {
                                extensions[extension.uuid] = {
@@ -210,9 +211,9 @@ GSC.sync = (function($) {
                                        local:          false
                                };
                        }
-               });
+               };
 
-               $.each(localExtensions, function(key, extension) {
+               for (const [key, extension] of Object.entries(localExtensions)) {
                        if(extensions[extension.uuid])
                        {
                                extensions[extension.uuid].name = extension.name;
@@ -230,7 +231,7 @@ GSC.sync = (function($) {
                                        local:          true
                                };
                        }
-               });
+               };
 
                return extensions;
        }
@@ -241,7 +242,7 @@ GSC.sync = (function($) {
        function localExtensionsChanged() {
                extensionChangedTimeout = false;
 
-               if (!$.isEmptyObject(extensionChangedQueue))
+               if (!isEmptyObject(extensionChangedQueue))
                {
                        GSC.sendNativeRequest({
                                execute: 'listExtensions'
@@ -251,11 +252,11 @@ GSC.sync = (function($) {
                                        chrome.storage.sync.get({
                                                extensions: {}
                                        }, function (options) {
-                                               $.each(extensionChangedQueue, function (extensionId, 
extension) {
-                                                       if ($.inArray(extension.state, 
[EXTENSION_STATE.ENABLED, EXTENSION_STATE.DISABLED, EXTENSION_STATE.UNINSTALLED]) !== -1)
+                                               for (const [extensionId, extension] of 
Object.entries(extensionChangedQueue)) {
+                                                       if ([EXTENSION_STATE.ENABLED, 
EXTENSION_STATE.DISABLED, EXTENSION_STATE.UNINSTALLED].includes(extension.state))
                                                        {
                                                                // Extension can be uninstalled already
-                                                               if (response.extensions[extensionId] && 
!$.isEmptyObject(response.extensions[extensionId]))
+                                                               if (response.extensions[extensionId] && 
!isEmptyObject(response.extensions[extensionId]))
                                                                {
                                                                        extension = 
response.extensions[extensionId];
                                                                }
@@ -273,7 +274,7 @@ GSC.sync = (function($) {
                                                                        };
                                                                }
                                                        }
-                                               });
+                                               };
 
                                                chrome.storage.sync.set({
                                                        extensions: options.extensions
@@ -296,10 +297,9 @@ GSC.sync = (function($) {
         * @param remoteExtensions - (optional) remote extensions list
         */
        function remoteExtensionsChanged(remoteExtensions) {
-
-               getExtensions($.Deferred().done(function(extensions) {
+               getExtensions(remoteExtensions).then((extensions) => {
                        var enableExtensions = [];
-                       $.each(extensions, function(uuid, extension) {
+                       for ([uuid, extension] of Object.entries(extensions)) {
                                if(extension.remote)
                                {
                                        if(!extension.local)
@@ -334,7 +334,7 @@ GSC.sync = (function($) {
                                                uuid: extension.uuid
                                        }, onInstallUninstall);
                                }
-                       });
+                       };
 
                        if(enableExtensions.length > 0)
                        {
@@ -343,9 +343,9 @@ GSC.sync = (function($) {
                                        extensions: enableExtensions
                                });
                        }
-               }).fail(function(message) {
+               }).catch((message) => {
                        createSyncFailedNotification(message);
-               }), remoteExtensions);
+               });
        }
 
        /*
@@ -452,4 +452,4 @@ GSC.sync = (function($) {
                getExtensions: getExtensions,
                onExtensionChanged: onExtensionChanged
        };
-})(jQuery);
+})();
diff --git a/extension/include/toolbar.js b/extension/include/toolbar.js
index 34e1a79..dc2c7ca 100644
--- a/extension/include/toolbar.js
+++ b/extension/include/toolbar.js
@@ -11,7 +11,7 @@
 /*
  * Main object that handles toolbar icon.
  */
-GSC.toolbar = (function($) {
+GSC.toolbar = (function() {
        /*
         * Initialization rutines.
         */
@@ -62,4 +62,4 @@ GSC.toolbar = (function($) {
        return {
                init: init
        };
-})(jQuery);
+})();
diff --git a/extension/include/update.js b/extension/include/update.js
index f7b9fb6..f7f91fa 100644
--- a/extension/include/update.js
+++ b/extension/include/update.js
@@ -8,7 +8,7 @@
     (at your option) any later version.
  */
 
-GSC.update = (function($) {
+GSC.update = (function() {
        function schedule(updateCheckPeriod, skipCheck) {
                if(!skipCheck)
                {
@@ -68,7 +68,7 @@ GSC.update = (function($) {
                var toUpgrade = [];
                for (uuid in data)
                {
-                       if (installedExtensions[uuid] && $.inArray(data[uuid], ['upgrade', 'downgrade']) !== 
-1)
+                       if (installedExtensions[uuid] && ['upgrade', 'downgrade'].includes(data[uuid]))
                        {
                                toUpgrade.push({
                                        title: installedExtensions[uuid].name,
@@ -94,7 +94,7 @@ GSC.update = (function($) {
 
        function init() {
                function onNotificationAction(notificationId, buttonIndex) {
-                       if ($.inArray(notificationId, [NOTIFICATION_UPDATE_AVAILABLE]) === -1)
+                       if (NOTIFICATION_UPDATE_AVAILABLE == notificationId)
                                return;
 
                        GSC.notifications.remove(notificationId);
@@ -201,4 +201,4 @@ GSC.update = (function($) {
                check: check,
                schedule: schedule
        };
-})(jQuery);
+})();
diff --git a/extension/manifest.json b/extension/manifest.json
index d21bad1..d1cd4bb 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -19,7 +19,6 @@
 
   "background": {
     "scripts": [
-      "include/external/jquery-2.1.4.js",
       "include/i18n.js",
       "include/constants.js",
       "include/compat-common.js",
diff --git a/extension/options.html b/extension/options.html
index 2b4984e..c8f809a 100644
--- a/extension/options.html
+++ b/extension/options.html
@@ -3,12 +3,7 @@
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title data-i18n="options_title, __MSG_gs_chrome__"></title>
-               <link href="css/dialog-polyfill.css" rel="stylesheet" type="text/css" />
-               <link href="css/tabby.min.css" rel="stylesheet" type="text/css" />
                <link href="css/options.css" rel="stylesheet" type="text/css" />
-               <script type="text/javascript" src="include/external/dialog-polyfill.js"></script>
-               <script type="text/javascript" src="include/external/jquery-3.6.0.js"></script>
-               <script type="text/javascript" src="include/external/tabby-10.1.0.js"></script>
                <script type="text/javascript" src="include/i18n.js"></script>
                <script type="text/javascript" src="include/constants.js"></script>
                <script type="text/javascript" src="include/compat-common.js"></script>
@@ -16,15 +11,15 @@
                <script type="text/javascript" src="include/sync.js"></script>
        </head>
        <body>
-               <ul data-tabs='tabs' class="tabs">
-                       <li><a href="#options" class='active' data-i18n='options_link' 
data-tab='tab'></a></li>
+               <ul data-tabs class="tabs">
+                       <li><a href="#options" data-tabs-active data-i18n='options_link' 
data-tab='tab'></a></li>
                        <li><a href="#synchronization" data-i18n='synchronization' data-tab='tab'></a></li>
                        <li class='translation_credits_container'><a href="#translation_credits" 
data-i18n='translation_credits_title' data-tab='tab'></a></li>
                </ul>
-               <div data-tabs-content='tabs-content'>
+               <div>
                        <div id="options" class="tabs-pane active" data-tabs-pane='tabs-pane'>
-                               <div id="status" data-i18n="options_saved"></div>
-                               <div id="error"></div>
+                               <div id="status" class="hide" data-i18n="options_saved"></div>
+                               <div id="error" class="hide"></div>
 
                                <fieldset>
                                        <dl>
diff --git a/extension/options.js b/extension/options.js
index a5efb2e..163f3c8 100644
--- a/extension/options.js
+++ b/extension/options.js
@@ -8,14 +8,39 @@
     (at your option) any later version.
  */
 
+function init_tabs()
+{
+       let tabLinks = $("[data-tabs]").querySelectorAll('a');
+       let updateTabs = (active = null) => {
+               tabLinks.forEach((link) => {
+                       let tab = $(link.getAttribute("href"));
+
+                       if((!active && link.hasAttribute('data-tabs-active')) || link == active) {
+                               tab.classList.remove('hide');
+                       }
+                       else {
+                               tab.classList.add('hide');
+                       }
+               });
+       };
+
+       tabLinks.forEach((link) => {
+               link.addEventListener('click', (event) => {
+                       updateTabs(event.target);
+               });
+       });
+
+       updateTabs();
+}
+
 function save_options()
 {
-       var showReleaseNotes = $('#show_release_notes_yes').prop('checked');
-       var syncExtensions = $('#synchronize_extensions_yes').prop('checked');
-       var updateCheck = $('#update_check_yes').prop('checked');
-       var updateCheckEnabledOnly = $('#update_check_enabled_yes').prop('checked');
-       var updateCheckPeriod = $('#update_check_period').val();
-       var useLightIcon = $('#use_light_icon_yes').prop('checked');
+       var showReleaseNotes = $('#show_release_notes_yes').checked;
+       var syncExtensions = $('#synchronize_extensions_yes').checked;
+       var updateCheck = $('#update_check_yes').checked;
+       var updateCheckEnabledOnly = $('#update_check_enabled_yes').checked;
+       var updateCheckPeriod = $('#update_check_period').value;
+       var useLightIcon = $('#use_light_icon_yes').checked;
        updateCheckPeriod = Math.max(3, updateCheckPeriod);
 
        chrome.storage.sync.set({
@@ -33,9 +58,9 @@ function save_options()
                                syncType = document.getElementById('syncChoice').returnValue;
                                if(!syncType || syncType === 'local')
                                {
-                                       GSC.sync.getExtensions($.Deferred().done(function (extensions) {
+                                       GSC.sync.getExtensions().then((extensions) => {
                                                var localExtensions = {};
-                                               $.each(extensions, function (uuid, extension) {
+                                               for (const [uuid, extension] of Object.entries(extensions)) {
                                                        if(extension.local && extension.localState != 
EXTENSION_STATE.UNINSTALLED)
                                                        {
                                                                localExtensions[extension.uuid] = {
@@ -44,20 +69,16 @@ function save_options()
                                                                        state:  extension.localState
                                                                };
                                                        }
-                                               });
+                                               };
 
                                                chrome.storage.sync.set({
                                                        extensions: localExtensions
                                                }, function() {
                                                        showSuccessStatus();
                                                });
-                                       }).fail(function (message) {
-                                               $('#error')
-                                                       .html(message)
-                                                       .show()
-                                                       .delay(15000)
-                                                       .hide(250);
-                                       }));
+                                       }).catch((message) => {
+                                               showWithDelay($('#error'), 15000, message);
+                                       });
                                }
                                else if(syncType === 'remote')
                                {
@@ -76,29 +97,26 @@ function save_options()
 function showSuccessStatus()
 {
        // Update status to let user know options were saved.
-       $('#status')
-               .show()
-               .delay(750)
-               .hide(250);
+       showWithDelay($('#status'), 750);
 }
 
 function restore_options()
 {
-       tabby.init();
+       init_tabs();
 
        chrome.storage.sync.get(DEFAULT_SYNC_OPTIONS, function (items) {
                function toggle_notice(show, id) {
                        let notice = $('#' + id)
                                .closest('dl')
-                               .find('dt br, dt span.notice');
+                               .querySelector('dt br, dt span.notice');
 
                        if (show)
                        {
-                               notice.show();
+                               notice.style.display = 'block';
                        }
                        else
                        {
-                               notice.hide();
+                               notice.style.display = 'none';
                        }
                }
 
@@ -143,8 +161,8 @@ function restore_options()
                        }
                        else
                        {
-                               $("input[name='update_check'], #update_check_period").removeAttr('disabled');
-                               $('#update_check_period').val(items.updateCheckPeriod);
+                               $$("input[name='update_check'], #update_check_period").forEach((input) => 
input.disabled = false);
+                               $('#update_check_period').value = items.updateCheckPeriod;
                                toggle_update_notice(false);
                                retrieveUpdateTimes();
                        }
@@ -155,7 +173,7 @@ function restore_options()
                        }
                        else
                        {
-                               $("input[name='update_check_enabled']").removeAttr('disabled');
+                               $("input[name='update_check_enabled']").disabled = false;
                                toggle_update_enable_notice(false);
                        }
 
@@ -174,8 +192,8 @@ function restore_options()
        }
        else
        {
-               $('a[data-i18n="synchronization"]').parent().remove();
-               $('#synchronize_extensions_yes').closest('dl').hide();
+               $('a[data-i18n="synchronization"]').parentNode.remove();
+               $('#synchronize_extensions_yes').closest('dl').style.display = 'none';
        }
 
        chrome.storage.local.get(DEFAULT_LOCAL_OPTIONS, function (items) {
@@ -203,11 +221,11 @@ function retrieveUpdateTimes()
        }, function (items) {
                if(items.lastUpdateCheck)
                {
-                       $('#last_update_check').text(items.lastUpdateCheck);
+                       $('#last_update_check').innerText = items.lastUpdateCheck;
                }
                else
                {
-                       $('#last_update_check').text(m('never'));
+                       $('#last_update_check').innerText = m('never');
                }
        });
 
@@ -219,11 +237,11 @@ function retrieveNextUpdateTime()
        chrome.alarms.get(ALARM_UPDATE_CHECK, function (alarm) {
                if (alarm)
                {
-                       $('#next_update_check').text(new Date(alarm.scheduledTime).toLocaleString());
+                       $('#next_update_check').innerText = new Date(alarm.scheduledTime).toLocaleString();
                }
                else
                {
-                       $('#next_update_check').text(m('never'));
+                       $('#next_update_check').innerText = m('never');
                }
        });
 }
@@ -231,46 +249,46 @@ function retrieveNextUpdateTime()
 function setCheckUpdate(result)
 {
        if(result)
-               $('#update_check_yes').prop('checked', true);
+               $('#update_check_yes').checked = true;
        else
-               $('#update_check_no').prop('checked', true);
+               $('#update_check_no').checked = true;
 }
 
 function setCheckUpdateEnabledOnly(result)
 {
        if(result)
-               $('#update_check_enabled_yes').prop('checked', true);
+               $('#update_check_enabled_yes').checked = true;
        else
-               $('#update_check_enabled_no').prop('checked', true);
+               $('#update_check_enabled_no').checked = true;
 }
 
 function setLightIcon(result)
 {
        if(result)
-               $('#use_light_icon_yes').prop('checked', true);
+               $('#use_light_icon_yes').checked = true;
        else
-               $('#use_light_icon_no').prop('checked', true);
+               $('#use_light_icon_no').checked = true;
 }
 
 function setReleaseNotes(result)
 {
        if(result)
-               $('#show_release_notes_yes').prop('checked', true);
+               $('#show_release_notes_yes').checked = true;
        else
-               $('#show_release_notes_no').prop('checked', true);
+               $('#show_release_notes_no').checked = true;
 }
 
 function setSyncExtensions(result)
 {
        if(result)
-               $('#synchronize_extensions_yes').prop('checked', true);
+               $('#synchronize_extensions_yes').checked = true;
        else
-               $('#synchronize_extensions_no').prop('checked', true);
+               $('#synchronize_extensions_no').checked = true;
 }
 
 function handleSynchronize()
 {
-       if($('#synchronize_extensions_yes').is(':checked'))
+       if($('#synchronize_extensions_yes').checked)
        {
                chrome.permissions.request({
                        permissions: ["idle"]
@@ -285,7 +303,7 @@ function handleSynchronize()
                                chrome.storage.sync.get({
                                        extensions: {}
                                }, function (options) {
-                                       if(!$.isEmptyObject(options.extensions))
+                                       if(!isEmptyObject(options.extensions))
                                        {
                                                document.getElementById('syncChoice').showModal();
                                        }
@@ -319,7 +337,7 @@ function handleSynchronize()
 
 function updateSynchronizationStatus()
 {
-       GSC.sync.getExtensions($.Deferred().done(function (extensions) {
+       GSC.sync.getExtensions().then((extensions) => {
                var keys = Object.keys(extensions).sort(function (a, b) {
                        var nameA = extensions[a].name.toLowerCase();
                        var nameB = extensions[b].name.toLowerCase();
@@ -337,39 +355,23 @@ function updateSynchronizationStatus()
                        return 0;
                });
 
-               $('#synchronization table tbody').empty();
-               $.each(keys, function (key, uuid) {
+               empty($('#synchronization table tbody'));
+               for (const [key, uuid] of Object.entries(keys)) {
                        var extension = extensions[uuid];
 
-                       $('#synchronization table tbody').append(
-                               $('<tr />')
-                                       .append(
-                                               $('<td />').text(extension.name)
-                                       )
-                                       .append(
-                                               $('<td />').addClass(
-                                                       extension.local ? 'ok' : 'fail'
-                                               )
-                                       )
-                                       .append(
-                                               $('<td />').addClass(
-                                                       extension.localState == EXTENSION_STATE.ENABLED ? 
'ok' : 'fail'
-                                               )
-                                       )
-                                       .append(
-                                               $('<td />').addClass(
-                                                       extension.remote ? 'ok' : 'fail'
-                                               )
-                                       )
+                       $('#synchronization table tbody').insertAdjacentHTML(
+                               'beforeEnd',
+                               `<tr>
+                                       <td>${extension.name}</td>
+                                       <td class='${extension.local && 'ok' || 'fail'}'></td>
+                                       <td class='${extension.localState == EXTENSION_STATE.ENABLED && 'ok' 
|| 'fail'}'></td>
+                                       <td class='${extension.remote && 'ok' || 'fail'}'></td>
+                               </tr>`
                        );
-               });
-       }).fail(function (message) {
-               $('#error')
-                       .html(message)
-                       .show()
-                       .delay(15000)
-                       .hide(250);
-       }));
+               };
+       }).catch((message) => {
+               showWithDelay($('#error'), 15000, message);
+       });
 }
 
 i18n();
@@ -377,13 +379,11 @@ i18n();
 document.addEventListener('DOMContentLoaded', restore_options);
 document.getElementById('save').addEventListener('click', save_options);
 
-$.each(document.getElementsByName('synchronize_extensions'), function(index, control) {
+document.getElementsByName('synchronize_extensions').forEach((control) => {
        control.addEventListener('change', handleSynchronize);
 });
 
 
-// Compat: Firefox
-dialogPolyfill.registerDialog(document.getElementById('syncChoice'));
 document.getElementById('syncChoice').addEventListener('close', function() {
        if(document.getElementById('syncChoice').returnValue === 'cancel')
        {
@@ -400,7 +400,7 @@ document.getElementById('syncChoice').addEventListener('close', function() {
        }
 });
 
-if($('#translation_credits div').is(':empty'))
+if(!$('#translation_credits div').firstChild)
 {
        $('.translation_credits_container').remove();
 }
@@ -410,7 +410,7 @@ chrome.storage.onChanged.addListener(function (changes, areaName) {
        {
                if(changes.lastUpdateCheck && changes.lastUpdateCheck.newValue)
                {
-                       $('#last_update_check').text(changes.lastUpdateCheck.newValue);
+                       $('#last_update_check').innerText = changes.lastUpdateCheck.newValue;
                }
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]