PageSourceSearch

https://aiwriter.fun/common/turnstile-risk.js?v1=v25

js aiwriter.fun collected 2026-10-02 13:27:49 UTC 4,046 bytes, 135 lines download raw bytes

1(function (window, document) {
2    'use strict';
3
4    var state = {
5        required: null,
6        loading: null,
7        widgetId: null
8    };
9
10    function container() {
11        return document.querySelector('[data-turnstile-container]');
12    }
13
14    function isRequired() {
15        if (state.required !== null) {
16            return state.required;
17        }
18
19        var node = container();
20        state.required = !!(node && node.getAttribute('data-required') === '1');
21        return state.required;
22    }
23
24    function loadApi() {
25        if (window.turnstile) {
26            return Promise.resolve();
27        }
28
29        if (state.loading) {
30            return state.loading;
31        }
32
33        state.loading = new Promise(function (resolve, reject) {
34            var existing = document.querySelector('script[data-turnstile-api]');
35            if (existing) {
36                existing.addEventListener('load', resolve, {once: true});
37                existing.addEventListener('error', reject, {once: true});
38                return;
39            }
40
41            var script = document.createElement('script');
42            script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
43            script.async = true;
44            script.defer = true;
45            script.setAttribute('data-turnstile-api', '1');
46            script.onload = resolve;
47            script.onerror = reject;
48            document.head.appendChild(script);
49        });
50
51        return state.loading;
52    }
53
54    function render() {
55        var node = container();
56        if (!node) {
57            return Promise.reject(new Error('Turnstile container is missing.'));
58        }
59
60        node.hidden = false;
61        node.removeAttribute('aria-hidden');
62
63        var widget = node.querySelector('.cf-turnstile');
64        if (!widget) {
65            widget = document.createElement('div');
66            widget.className = 'cf-turnstile';
67            widget.setAttribute('data-theme', 'light');
68            widget.setAttribute('data-sitekey', node.getAttribute('data-sitekey') || '');
69            node.appendChild(widget);
70        }
71
72        return loadApi().then(function () {
73            if (state.widgetId !== null || !window.turnstile || !widget) {
74                return;
75            }
76
77            state.widgetId = window.turnstile.render(widget, {
78                sitekey: widget.getAttribute('data-sitekey'),
79                theme: 'light'
80            });
81        });
82    }
83
84    function requireChallenge() {
85        state.required = true;
86        return render();
87    }
88
89    function token() {
90        var input = document.querySelector('[name="cf-turnstile-response"]');
91        return input && input.value ? input.value : '';
92    }
93
94    function reset() {
95        if (window.turnstile) {
96            if (state.widgetId !== null) {
97                window.turnstile.reset(state.widgetId);
98            } else {
99                window.turnstile.reset();
100            }
101        }
102    }
103
104    window.TurnstileRisk = {
105        isRequired: isRequired,
106        require: requireChallenge,
107        token: token,
108        reset: reset
109    };
110
111    if (window.jQuery && window.jQuery.ajaxPrefilter) {
112        window.jQuery.ajaxPrefilter(function (options) {
113            var success = options.success;
114            options.success = function (response) {
115                if (response && response.turnstile_required) {
116                    requireChallenge().catch(function () {
117                        // The page-specific handler will show the request failure.
118                    });
119                }
120
121                if (typeof success === 'function') {
122                    return success.apply(this, arguments);
123                }
124            };
125        });
126    }
127
128    if (isRequired()) {
129        document.addEventListener('DOMContentLoaded', function () {
130            requireChallenge().catch(function () {
131                // The action request will show the same verification state if loading fails.
132            });
133        });
134    }
135})(window, document);

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.