PageSourceSearch

https://www.a5.org.cn/wp-content/mu-plugins/a5-sf-frontend.js?ver=1.0.0

js a5.org.cn collected 2026-10-06 23:49:57 UTC 8,390 bytes, 201 lines download raw bytes

1/* A5 Share For Invitation - Frontend JS */
2/* 独立 JS 文件,避免被缓存插件或主题优化破坏 */
3(function($) {
4    'use strict';
5
6    // 等待 DOM 加载
7    $(function() {
8
9        // ========== 工具函数:获取翻译文本(兜底) ==========
10        function t(key) {
11            if (window.a5_sf_data && window.a5_sf_data.i18n && window.a5_sf_data.i18n[key]) {
12                return window.a5_sf_data.i18n[key];
13            }
14            // 兜底中文值
15            var fallback = {
16                'gen_btn_default': '🔗 生成链接',
17                'gen_btn_loading': '生成中...',
18                'copied': '✅ 已复制',
19                'submit_default': '🚀 提交审核',
20                'submit_loading': '提交中...',
21                'err_network': '网络错误,请重试',
22                'err_no_identifier': '请先填写标识',
23                'err_no_ref': '请先生成专属链接',
24                'hint_email': '邀请码将发送到此邮箱',
25                'hint_wechat': '请填写真实微信号,用于客服核验',
26                'hint_qq': '请填写真实QQ号,用于客服核验',
27                'ph_email': '[email protected]',
28                'ph_wechat': '如 wxid_xxx 或 微信号',
29                'ph_qq': '如 123456789'
30            };
31            return fallback[key] || key;
32        }
33
34        function getAjaxUrl() {
35            if (window.a5_sf_data && window.a5_sf_data.ajaxurl) return window.a5_sf_data.ajaxurl;
36            if (window.ajaxurl) return window.ajaxurl;
37            return '/wp-admin/admin-ajax.php';
38        }
39
40        function getNonce() {
41            if (window.a5_sf_data && window.a5_sf_data.nonce) return window.a5_sf_data.nonce;
42            return '';
43        }
44
45        // ========== 切换标识类型时更新提示 ==========
46        $(document).on('change', 'input[name="identifier_type"]', function() {
47            var type = $(this).val();
48            $('#a5_identifier_hint').text(t('hint_' + type));
49            $('#a5_identifier').attr('placeholder', t('ph_' + type));
50        });
51
52        // ========== 生成链接 ==========
53        $(document).on('click', '#a5_gen_btn', function(e) {
54            e.preventDefault();
55            var $btn = $(this);
56            var identifier = $('#a5_identifier').val().trim();
57            var type = $('input[name="identifier_type"]:checked').val();
58
59            if (!identifier) {
60                alert(t('err_no_identifier'));
61                $('#a5_identifier').focus();
62                return;
63            }
64
65            $btn.text(t('gen_btn_loading')).prop('disabled', true);
66
67            $.ajax({
68                url: getAjaxUrl(),
69                type: 'POST',
70                dataType: 'json',
71                data: {
72                    action: 'a5_gen_share_link',
73                    nonce: getNonce(),
74                    identifier: identifier,
75                    type: type
76                },
77                timeout: 15000
78            }).done(function(resp) {
79                $btn.text(t('gen_btn_default')).prop('disabled', false);
80                if (resp && resp.success) {
81                    $('#a5_share_url').val(resp.data.share_url).prop('readonly', false);
82                    $('#a5_ref_code').text(resp.data.ref_code);
83                    $('#a5_link_box').slideDown(300);
84                    // 同步到表单 hidden 字段
85                    $('#a5_form_identifier').val(identifier);
86                    $('#a5_form_type').val(type);
87                    $('#a5_form_ref_code').val(resp.data.ref_code);
88                    // 滚动到链接区
89                    $('html, body').animate({
90                        scrollTop: $('#a5_link_box').offset().top - 100
91                    }, 500);
92                } else {
93                    var msg = (resp && resp.data && resp.data.message) ? resp.data.message : '生成失败';
94                    alert(msg);
95                }
96            }).fail(function(xhr, status) {
97                $btn.text(t('gen_btn_default')).prop('disabled', false);
98                console.error('A5 SF Generate Error:', status, xhr.responseText);
99                alert(t('err_network') + '\n\n' + (xhr.responseText ? xhr.responseText.substring(0, 200) : ''));
100            });
101        });
102
103        // ========== 复制链接 ==========
104        $(document).on('click', '#a5_copy_btn', function(e) {
105            e.preventDefault();
106            var input = document.getElementById('a5_share_url');
107            if (!input) return;
108            input.select();
109            input.setSelectionRange(0, 99999);
110
111            var $btn = $(this);
112            var orig = $btn.text();
113
114            // 优先使用 Clipboard API
115            if (navigator.clipboard && navigator.clipboard.writeText) {
116                navigator.clipboard.writeText(input.value).then(function() {
117                    $btn.text(t('copied'));
118                    setTimeout(function() { $btn.text(orig); }, 2000);
119                }).catch(function() {
120                    fallbackCopy(input, $btn, orig);
121                });
122            } else {
123                fallbackCopy(input, $btn, orig);
124            }
125        });
126
127        function fallbackCopy(input, $btn, orig) {
128            try {
129                document.execCommand('copy');
130                $btn.text(t('copied'));
131                setTimeout(function() { $btn.text(orig); }, 2000);
132            } catch (err) {
133                alert('请手动复制:' + input.value);
134            }
135        }
136
137        // ========== 提交表单 ==========
138        $(document).on('submit', '#a5_submit_form', function(e) {
139            e.preventDefault();
140            if (!$('#a5_form_ref_code').val()) {
141                alert(t('err_no_ref'));
142                $('html, body').animate({
143                    scrollTop: $('#a5_identifier').offset().top - 100
144                }, 500);
145                return;
146            }
147
148            var $btn = $('.a5-sf-btn-submit');
149            $btn.text(t('submit_loading')).prop('disabled', true);
150
151            var formData = $(this).serialize();
152            // 确保包含 action 和 nonce
153            if (formData.indexOf('action=') === -1) {
154                formData += '&action=a5_submit_share';
155            }
156            if (formData.indexOf('nonce=') === -1) {
157                formData += '&nonce=' + getNonce();
158            }
159
160            $.ajax({
161                url: getAjaxUrl(),
162                type: 'POST',
163                dataType: 'json',
164                data: formData,
165                timeout: 20000
166            }).done(function(resp) {
167                $btn.text(t('submit_default')).prop('disabled', false);
168                var $msg = $('#a5_submit_msg');
169                $msg.show().removeClass('a5-sf-msg-success a5-sf-msg-error');
170
171                if (resp && resp.success) {
172                    $msg.addClass('a5-sf-msg-success').html(
173                        '✅ ' + resp.data.message + '<br><br>' +
174                        '📌 请立即扫码加客服微信,发送:<br>' +
175                        '1. 你的标识(邮箱/微信/QQ)<br>' +
176                        '2. 分享页面截图<br><br>' +
177                        '客服将在 30 分钟内审核并发邀请码到你的邮箱。'
178                    );
179                    $('#a5_submit_form')[0].reset();
180                    $('#a5_form_identifier, #a5_form_type, #a5_form_ref_code').val('');
181                    $('#a5_link_box').slideUp(300);
182                } else {
183                    $msg.addClass('a5-sf-msg-error').text(
184                        '❌ ' + ((resp && resp.data && resp.data.message) ? resp.data.message : '提交失败')
185                    );
186                }
187                $('html, body').animate({
188                    scrollTop: $msg.offset().top - 100
189                }, 500);
190            }).fail(function(xhr, status) {
191                $btn.text(t('submit_default')).prop('disabled', false);
192                console.error('A5 SF Submit Error:', status, xhr.responseText);
193                var $msg = $('#a5_submit_msg');
194                $msg.show().removeClass('a5-sf-msg-success').addClass('a5-sf-msg-error').text(
195                    '❌ ' + t('err_network') + '\n\n' + (xhr.responseText ? xhr.responseText.substring(0, 200) : '')
196                );
197            });
198        });
199
200    });
201})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.