Browse Source

chore: remove duplicated jq binding

M1Screw 1 year ago
parent
commit
f097d98a50

+ 1 - 7
public/assets/js/fuck.js

@@ -5,7 +5,7 @@
     const hasMime = function (option, value) {
         const mimeTypes = navigator.mimeTypes;
         for (const mt in mimeTypes) {
-            if (mimeTypes[mt][option] == value) {
+            if (mimeTypes[mt][option] === value) {
                 return true;
             }
         }
@@ -68,12 +68,6 @@
         is360 = true;
     }
 
-    for (const key in navigator.plugins) {
-        if (navigator.plugins[key].filename == 'internal-nacl-plugin') {
-            is360 = true;
-        }
-    }
-
     if (
         matchUserAgent('MSIE') ||
         matchUserAgent('Trident') ||

+ 5 - 4
resources/views/tabler/gateway/f2f.tpl

@@ -13,6 +13,7 @@
 
 <script>
     let pid = 0;
+    let f2fQrcode = $('#f2fpay-button');
 
     function f2fpay() {
         $.ajax({
@@ -25,9 +26,9 @@
             },
             success: (data) => {
                 if (data.ret === 1) {
-                    $('#f2fpay-button').remove();
+                    f2fQrcode.remove();
                     pid = data.pid;
-                    $('#f2f-qrcode').append('<div class="text-center"><p>手机支付宝扫描支付</p></div>');
+                    f2fQrcode.append('<div class="text-center"><p>手机支付宝扫描支付</p></div>');
                     new QRCode("f2f-qrcode", {
                         text: data.qrcode,
                         width: 200,
@@ -36,8 +37,8 @@
                         colorLight: '#ffffff',
                         correctLevel: QRCode.CorrectLevel.H,
                     });
-                    $('#f2f-qrcode').append('<div class="text-center my-3"><p>支付成功后请手动刷新页面</p></div>');
-                    $('#f2f-qrcode').attr('href', data.qrcode);
+                    f2fQrcode.append('<div class="text-center my-3"><p>支付成功后请手动刷新页面</p></div>');
+                    f2fQrcode.attr('href', data.qrcode);
                 } else {
                     $('#fail-message').text(data.msg);
                     $('#fail-dialog').modal('show');

+ 28 - 28
resources/views/tabler/user/edit.tpl

@@ -537,22 +537,24 @@
         });
 
         {if $user->im_type === 0 && $user->im_value === ''}
+        let oauthProvider = $('#oauth-provider');
+
         $("#imtype").on('change', function () {
             if ($(this).val() === '0') {
-                $('#oauth-provider').empty();
+                oauthProvider.empty();
             } else if ($(this).val() === '1') {
-                $('#oauth-provider').empty();
-                $('#oauth-provider').append(
+                oauthProvider.empty();
+                oauthProvider.append(
                     "<a id='bind-slack' class='btn btn-azure ms-auto'>绑定 Slack</a>"
                 );
             } else if ($(this).val() === '2') {
-                $('#oauth-provider').empty();
-                $('#oauth-provider').append(
+                oauthProvider.empty();
+                oauthProvider.append(
                     "<a id='bind-discord' class='btn btn-indigo ms-auto'>绑定 Discord</a>"
                 );
             } else if ($(this).val() === '4') {
-                $('#oauth-provider').empty();
-                $('#oauth-provider').append(
+                oauthProvider.empty();
+                oauthProvider.append(
                     '<script async src=\"https://telegram.org/js/telegram-widget.js?22\"' +
                     ' data-telegram-login=\"' + "{$public_setting['telegram_bot']}" +
                     '\" data-size=\"large" data-onauth=\"onTelegramAuth(user)\"' +
@@ -561,34 +563,24 @@
             }
         });
 
-        $('#oauth-provider').on('click', '#bind-slack', function () {
+        oauthProvider.on('click', '#bind-slack', function () {
             $.ajax({
                 type: "POST",
                 url: "/oauth/slack",
                 dataType: "json",
                 success: function (data) {
-                    if (data.ret === 1) {
-                        window.location.replace(data.redir);
-                    } else {
-                        $('#fail-message').text(data.msg);
-                        $('#fail-dialog').modal('show');
-                    }
+                    handleOauthResult(data, 'slack')
                 }
             })
         });
 
-        $('#oauth-provider').on('click', '#bind-discord', function () {
+        oauthProvider.on('click', '#bind-discord', function () {
             $.ajax({
                 type: "POST",
                 url: "/oauth/discord",
                 dataType: "json",
                 success: function (data) {
-                    if (data.ret === 1) {
-                        window.location.replace(data.redir);
-                    } else {
-                        $('#fail-message').text(data.msg);
-                        $('#fail-dialog').modal('show');
-                    }
+                    handleOauthResult(data, 'discord')
                 }
             })
         });
@@ -602,16 +594,24 @@
                     user: JSON.stringify(user),
                 },
                 success: function (data) {
-                    if (data.ret === 1) {
-                        $('#success-message').text(data.msg);
-                        $('#success-dialog').modal('show');
-                    } else {
-                        $('#error-message').text(data.msg);
-                        $('#fail-dialog').modal('show');
-                    }
+                    handleOauthResult(data, 'telegram')
                 }
             })
         }
+
+        function handleOauthResult(data, type = 'telegram') {
+            if (data.ret === 1) {
+                if (type === 'telegram') {
+                    $('#success-message').text(data.msg);
+                    $('#success-dialog').modal('show');
+                } else {
+                    window.location.replace(data.redir);
+                }
+            } else {
+                $('#error-message').text(data.msg);
+                $('#fail-dialog').modal('show');
+            }
+        }
         {/if}
     </script>