PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 2.5.6
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v2.5.6
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / assets / js / report_script.js

report_script.js in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 2.5.6, at assets/js/report_script.js

92 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(w, d) {
2 w.addEventListener("load", async function () {
3 let optmlAdmin = document.querySelector("li#wp-admin-bar-optml_report_script ul#wp-admin-bar-optml_report_script-default");
4 optmlAdmin.addEventListener("click", function () {
5 if (typeof reportScript !== 'undefined') {
6 let body = document.getElementsByTagName('body')[0];
7
8 let modal = document.createElement('div');
9 modal.setAttribute('class', 'optml-modal');
10 let modalContent = document.createElement('div');
11 modalContent.setAttribute('class', 'optml-modal-content');
12 let modalClose = document.createElement('span');
13 modalClose.setAttribute('class', 'optml-close');
14 modalClose.innerHTML = "&times";
15 modalClose.addEventListener("click" , function() {
16 modal.style.display = "none";
17 });
18 let modalText = document.createElement('div');
19 let modalTitle = document.createElement('p');
20 modalTitle.innerHTML = reportScript.description;
21 modalTitle.style.textAlign = "center";
22 modalText.innerHTML = reportScript.wait;
23 modalContent.appendChild(modalClose);
24 modalContent.appendChild(modalTitle);
25 modalContent.appendChild(modalText);
26 modal.appendChild(modalContent);
27 let report = '';
28 let optmlAdmin = document.querySelector("li#wp-admin-bar-optml_report_script ul#wp-admin-bar-optml_report_script-default");
29 modal.style.display = "block";
30 w.addEventListener( "click", function(event) {
31 if (event.target == modal) {
32 modal.style.display = "none";
33 }
34 });
35 body.appendChild(modal);
36 let pageImages = document.getElementsByTagName('img');
37 let imagesAdd = {};
38 for (let i = 0; i < pageImages.length; i++) {
39 let words = pageImages[i].src.split('://');
40 if (words.length <= 1) {
41 continue;
42 }
43 let domain = words[words.length - 1].split('/')[0];
44 let isIgnored = false;
45 for(idomain in reportScript.ignoredDomains){
46
47 if (domain.includes(reportScript.ignoredDomains[idomain])) {
48 isIgnored = true;
49 break;
50 }
51 }
52 if (isIgnored) {
53 continue;
54 }
55 if (!words[1].includes(reportScript.optmlCdn)) {
56 if (imagesAdd.hasOwnProperty(domain)) {
57 if (imagesAdd[domain].hasOwnProperty("ignoredUrls")) {
58 imagesAdd[domain]["ignoredUrls"]++;
59 continue;
60 }
61 }
62 imagesAdd[domain] = Object.assign({ignoredUrls: 1}, imagesAdd[domain]);
63 continue;
64 }
65 if (imagesAdd.hasOwnProperty(domain)) {
66 if (imagesAdd[domain].hasOwnProperty("src")) {
67 imagesAdd[domain]["src"].push(pageImages[i].src);
68 continue;
69 }
70 }
71 imagesAdd[domain] = Object.assign({src: Array(pageImages[i].src)}, imagesAdd[domain]);
72 }
73 fetch(reportScript.restUrl, {
74 method: 'POST',
75 mode: 'cors',
76 cache: 'no-cache',
77 credentials: 'same-origin',
78 headers: {
79 'X-WP-Nonce': reportScript.nonce,
80 'Content-Type': 'application/json'
81 },
82 referrerPolicy: 'no-referrer',
83 body: JSON.stringify({images: imagesAdd})
84 }).then(response => {
85 response.json().then(function (data) {
86 modalText.innerHTML =`${data.data}`;
87 });
88 });
89 }
90 });
91 });
92 }(window, document));