PageSourceSearch

https://openaudible.org/scripts/global.js

js openaudible.org collected 2026-09-24 19:41:50 UTC 3,943 bytes, 138 lines download raw bytes

1function error(message) {
2    return response('pa3 ba b--red bg-washed-red', message);
3}
4
5function success(message) {
6    // class=""  or class=""
7    return response('pa3 ba b--green bg-washed-green', message);
8}
9
10function response(clz, what) {
11    let successMessage = document.createElement('p');
12    successMessage.textContent = what;
13    let div = document.getElementById('message');
14    if (div) {
15        div.setAttribute('class', clz);
16        div.innerHTML = '';
17        div.appendChild(successMessage);
18    } else {
19        console.log("No message div found.");
20    }
21    return successMessage;
22}
23
24function setHiddenById(id, hidden) {
25    var element = document.getElementById(id);
26    if (element) {
27        if (hidden) {
28            element.classList.add('dn');
29        } else {
30            element.classList.remove('dn');
31        }
32    } else {
33        console.error('Element with id ' + id + ' not found.');
34    }
35
36}
37
38function requestWithResponse(method, path, success_msg, success_callback) {
39
40    fetch(path, {
41        method: method, // or 'GET' depending on your API
42    })
43        .then(response => response.json())
44        .then(data => {
45            if (data.error) {
46                // If there is an error, display it
47                error(data.error);
48            } else {
49                // Display the success message
50                if (success_msg)
51                    success(success_msg);
52                if (success_callback) {
53                    success_callback(data);
54                }
55            }
56        })
57        .catch(err => {
58            console.log(path+ ' error:', err);
59            error('An error occurred, please try again later.\n' + err);
60        });
61
62}
63
64function closeMobileMenu() {
65    var elements = document.querySelectorAll('.mobile-menu-drawer');
66    for (var i = 0; i < elements.length; i++) {
67        elements[i].classList.add('dn');
68    }
69}
70
71function showMobileMenu() {
72    var elements = document.querySelectorAll('.mobile-menu-drawer');
73    for (var i = 0; i < elements.length; i++) {
74        elements[i].classList.remove('dn');
75    }
76}
77
78function isLicenseString(str) {
79    // Regex to match the pattern
80    const licenseRegex = /^[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}$/;
81
82    // Test the string against the regex
83    return licenseRegex.test(str);
84}
85
86
87function copyToClipboard(copyDiv, confirmDiv) {
88    // Get the text from the div
89    var textToCopy = document.getElementById(copyDiv).innerText;
90    // Use the Clipboard API to copy the text
91    navigator.clipboard.writeText(textToCopy).then(function () {
92        // Show confirmation message
93        var confirmationMsg = document.getElementById(confirmDiv ? confirmDiv : 'confirmationMessage');
94        confirmationMsg.style.display = "inline";
95        // Hide confirmation message after 2 seconds
96        setTimeout(function () {
97            confirmationMsg.style.display = "none";
98        }, 2000);
99    }, function (err) {
100        console.error('Error in copying text: ', err);
101    });
102}
103
104function addContentAnchors() {
105    let contentID = 'content';
106    var map = {};
107    var content = document.getElementById(contentID);
108    if (!content) return;
109    var headings = content.querySelectorAll('h1, h2, h3');
110    for (var i = 0; i < headings.length; i++) {
111        var heading = headings[i];
112
113        var name = heading.textContent;
114        var headingId = heading.id;
115
116        if (!headingId) {
117            headingId = name
118                .trim()
119                .replace(/ /g, '_')
120                .replace(/([^A-Za-z0-9[\]{}_.:-])\s?/g, '')
121                .toLowerCase();
122        }
123
124        if (map[headingId]) {
125            headingId += 'x';
126            console.log('duplicate heading ' + headingId);
127        }
128
129        heading.setAttribute('id', headingId);
130        heading.insertAdjacentHTML(
131            'beforeend',
132            "<a class='heading-link' href='#" + headingId + "'></a>"
133        );
134
135    }
136
137}
138

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.