SHOW:
|
|
- or go back to the newest paste.
1 | var hzAdDebug = !1, | |
2 | hzVersion = "4.16", | |
3 | keywords, adCont, urlPrefix = !hzAdDebug && "https:" == location.protocol ? "https://ssl14.ovh.net/~hoverzoo" : "http://hoverzoom.net", | |
4 | validGeoC = ["us"]; | |
5 | ||
6 | function addAffiliateLinks() { | |
7 | try { | |
8 | if ("www.youtube.com" == location.host) { | |
9 | for (var a = null, c = null, b = document.querySelectorAll("#watch-description-extra-info .metadata-info-title"), d = 0; d < b.length; d++) 0 == b[d].textContent.indexOf("Buy") && (a = b[d].textContent.match(/Buy "(.*)" on/)) && (a = a[1]), -1 < b[d].textContent.indexOf("Artist") && (c = b[d].nextSibling.nextSibling.textContent); | |
10 | if (null === a || null === c) return; | |
11 | var e = c + " " + a, | |
12 | l = document.querySelectorAll('.metadata-info a[href*="itunes"], .metadata-info a[href*="googlemusic"]'); | |
13 | if (0 == l.length) return; | |
14 | var l = l[0], | |
15 | g = document.createElement("a"); | |
16 | g.target = "_blank"; | |
17 | g.className = "nowrap"; | |
18 | g.textContent = "Amazon"; | |
19 | g.title = 'Buy "' + a + '" on Amazon by courtesy of Hover Zoom'; | |
20 | g.href = "http://www.amazon.com/gp/search?ie=UTF8&camp=1789&creative=9325&index=music&keywords=" + encodeURIComponent(e) + "&linkCode=ur2&tag=hzyt-20"; | |
21 | l.parentElement.appendChild(g) | |
22 | } | |
23 | var n = Math.random(); | |
24 | if ("www.facebook.com" == location.host && (0.7 > n || hzAdDebug)) | |
25 | if (adCont = document.getElementById("pagelet_ego_pane")) { | |
26 | var e = "_default", | |
27 | m = localStorage["hzLinkCache " + e]; | |
28 | m && (m = JSON.parse(m)).expiration > Date.now() ? createAffiliatelinks(m) : (localStorage.removeItem("hzLinkCache " + e), getCountry(function (a) { | |
29 | -1 < validGeoC.indexOf(a) && searchItems(e, a, function (a) { | |
30 | a = JSON.parse(a); | |
31 | keywordsLinks = { | |
32 | links: [] | |
33 | }; | |
34 | if (a && a.links && 0 < a.links.length) | |
35 | for (var b = 0, d = a.links.length; b < d; b++) { | |
36 | var c = a.links[b]; | |
37 | (c.keywords == e || !c.keywords && "_default" == e) && keywordsLinks.links.push(c) | |
38 | } | |
39 | keywordsLinks.expiration = Date.now() + 6048E5; | |
40 | localStorage["hzLinkCache " + e] = JSON.stringify(keywordsLinks); | |
41 | createAffiliatelinks(keywordsLinks) | |
42 | }) | |
43 | })) | |
44 | } | |
45 | } catch (p) { | |
46 | if (hzAdDebug) throw p; | |
47 | } | |
48 | } | |
49 | ||
50 | function getCountry(a) { | |
51 | var c = document.cookie.match(/hzGeoC=(\w*)/); | |
52 | c && 2 == c.length ? a(c[1]) : chrome.runtime.sendMessage({ | |
53 | action: "ajaxGet", | |
54 | url: urlPrefix + "/api/geoc.php" | |
55 | }, function (b) { | |
56 | b = b.toLowerCase(); | |
57 | document.cookie = "hzGeoC=" + b + "; expires=" + (new Date(Date.now() + 2592E6)).toUTCString() + "; path=/"; | |
58 | a && a(b) | |
59 | }) | |
60 | } | |
61 | ||
62 | function searchItems(a, c, b) { | |
63 | chrome.runtime.sendMessage({ | |
64 | action: "ajaxGet", | |
65 | url: urlPrefix + "/api/amazonlinks/" + c + ".json" | |
66 | }, function (a) { | |
67 | try { | |
68 | a && (a = a.substr(a.indexOf("{")), hzAdDebug && console.log(a), b(a)) | |
69 | } catch (c) { | |
70 | if (hzAdDebug) throw c; | |
71 | } | |
72 | }) | |
73 | } | |
74 | ||
75 | function createAffiliatelinks(a) { | |
76 | try { | |
77 | if (a && a.links && a.links.length) { | |
78 | for (var c = 0, b = a.links[Math.floor(Math.random() * a.links.length)], d = Date.parse(b.start), e = Date.parse(b.end), l = Date.parse((new Date).toDateString()); !(d <= l && l <= e) && 5 > c++;) b = a.links[Math.floor(Math.random() * a.links.length)], d = Date.parse(b.start), e = Date.parse(b.end); | |
79 | var g = b.title || keywords || "", | |
80 | n = b.text + "<br>", | |
81 | m = b.list_price || b.best_price, | |
82 | p = b.img_url, | |
83 | k = adCont.querySelector("[data-ad]"); | |
84 | if (n && b.url) { | |
85 | for (; null != k && -1 == k.className.indexOf("ego_unit_container");) k = | |
86 | k.parentElement; | |
87 | if (null != k) { | |
88 | p || (p = chrome.extension.getURL("images/fb-amazon.png")); | |
89 | m && (n += "<br><b>" + m + "</b>"); | |
90 | var f = '<div class="uiSelector inlineBlock emu_x emuEventfad_hide fbEmuLink uiSelectorRight"><div class="wrap"><a id="hzCloseAd" style="visibility: hidden" href="http://hoverzoom.net/aboutads/" target="_blank" title="About this ad"><img src="' + chrome.extension.getURL("images/fb-close.png") + '"></a></div></div>', | |
91 | f = f + ('<div class="title" style="color: #3B5998; font-weight: bold; margin-bottom: 4px"><a class="forceLTR" href="' + | |
92 | b.url + '" target="_blank">' + g + "</a></div>"), | |
93 | f = f + ('<div class="clearfix image_body_block"><a class="emuEvent1 _24x image fbEmuImage _8o _8s lfloat" href="' + b.url + '" target="_blank">'), | |
94 | f = f + ('<img src="' + p + '" style="max-width: 100px; max-height: 72px"></a><div>'), | |
95 | f = f + ('<div class="_8m"><div class="body"><a class="forceLTR emuEvent1" style="color: #333; text-decoration: none;" href="' + b.url + '" target="_blank">' + n + "</a></div></div>"), | |
96 | f = f + "</div>"; | |
97 | window.removeEventListener("DOMNodeInserted", windowOnDOMNodeInserted); | |
98 | var h = document.createElement("div"); | |
99 | h.id = "hoverZoomAd"; | |
100 | h.className = "ego_unit"; | |
101 | h.dataset.keywords = g.replace(/['"]/g, " "); | |
102 | h.innerHTML = f; | |
103 | k.insertBefore(h, k.children[Math.floor(Math.random() * k.childElementCount)]); | |
104 | window.addEventListener("DOMNodeInserted", windowOnDOMNodeInserted); | |
105 | var q = document.getElementById("hzCloseAd"); | |
106 | h.addEventListener("mouseover", function () { | |
107 | q.style.visibility = "visible" | |
108 | }); | |
109 | h.addEventListener("mouseout", function () { | |
110 | q.style.visibility = "hidden" | |
111 | }); | |
112 | chrome.runtime.sendMessage({ | |
113 | action: "trackEvent", | |
114 | event: { | |
115 | category: "Ads", | |
116 | action: "FacebookAdDisplayed", | |
117 | label: h.dataset.keywords | |
118 | } | |
119 | }); | |
120 | h.addEventListener("click", function () { | |
121 | chrome.runtime.sendMessage({ | |
122 | action: "trackEvent", | |
123 | event: { | |
124 | category: "Ads", | |
125 | action: "FacebookAdClicked", | |
126 | label: this.dataset.keywords | |
127 | } | |
128 | }) | |
129 | }) | |
130 | } | |
131 | } | |
132 | } | |
133 | } catch (r) { | |
134 | if (hzAdDebug) throw r; | |
135 | } | |
136 | } | |
137 | ||
138 | function windowOnDOMNodeInserted(a) { | |
139 | a.target && ("ego_column" == a.target.className && a.target.parentElement && "pagelet_ego_pane" == a.target.parentElement.id && !document.getElementById("hoverZoomAd")) && addAffiliateLinks(); | |
140 | a.target && ("egoRefreshAds" == a.target.id && !document.getElementById("hoverZoomAd")) && addAffiliateLinks() | |
141 | } | |
142 | chrome.runtime.sendMessage({ | |
143 | action: "getOptions" | |
144 | }, function (a) { | |
145 | 2 > a.enableAds && addAffiliateLinks() | |
146 | }); |