Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BEFORE
- const extractAdUnitId = (input) => {
- const match = input.match(/_A\.(\d+)\./);
- return match ? match[1] : "";
- };
- const divElement = document.createElement("div");
- const baseUrl = "https://img.gsmarena.com/banner.php3";
- const params = new URLSearchParams({
- adUnitID: `${extractAdUnitId("/8095840/.2_A.35723.3_gsmarena.com_tier1")}`,
- pageid: "71",
- country: "BG",
- lpe: "low",
- keyw: "Apple",
- visitqos: "0",
- });
- const url = `${baseUrl}?${params.toString()}`;
- divElement.style.width = "728px";
- divElement.style.height = "94px";
- divElement.style.overflow = "auto";
- document.body.appendChild(divElement);
- const xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- const HTMLParser = new DOMParser();
- const parsedDocument = HTMLParser.parseFromString(this.responseText, "text/html");
- divElement.innerHTML = `${parsedDocument.head.innerHTML}${parsedDocument.body.innerHTML}`; // <-- this line
- }
- };
- xhr.open("GET", url, true);
- xhr.send();
- // AFTER
- const extractAdUnitId = (input) => {
- const match = input.match(/_A\.(\d+)\./);
- return match ? match[1] : "";
- };
- const divElement = document.createElement("div");
- const baseUrl = "https://img.gsmarena.com/banner.php3";
- const params = new URLSearchParams({
- adUnitID: `${extractAdUnitId("/8095840/.2_A.35723.3_gsmarena.com_tier1")}`,
- pageid: "71",
- country: "BG",
- lpe: "low",
- keyw: "Apple",
- visitqos: "0",
- });
- const url = `${baseUrl}?${params.toString()}`;
- divElement.style.width = "728px";
- divElement.style.height = "94px";
- divElement.style.overflow = "auto";
- document.body.appendChild(divElement);
- const xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- const HTMLParser = new DOMParser();
- const parsedDocument = HTMLParser.parseFromString(this.responseText, "text/html");
- const fragment = document.createRange().createContextualFragment(`${parsedDocument.head.innerHTML}${parsedDocument.body.innerHTML}`);
- divElement.appendChild(fragment);
- }
- };
- xhr.open("GET", url, true);
- xhr.send();
Advertisement
Add Comment
Please, Sign In to add comment