-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontentscript.js
More file actions
55 lines (49 loc) · 1.67 KB
/
contentscript.js
File metadata and controls
55 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var re = /ISBN[:\s]*([X0-9\\-]*)/g;
rawISBN = document.body.innerText.match(re)[0];
isbn = rawISBN.replace(/-/g, "").slice(-10, -1)
function createRootElement(id) {
root = document.createElement("div");
root.id = id;
root.style.backgroundColor = "#00FF00";
root.style.height = "25px";
root.style.fontFamily = "Trebuchet MS";
root.style.fontSize = "12px";
root.style.verticalAlign = "middle";
root.style.textAlign = "center";
document.body.insertBefore(root, document.body.firstChild);
return root;
}
function showBooks(responseText) {
parser=new DOMParser();
responseXML=parser.parseFromString(responseText,"text/xml");
var books = responseXML.getElementsByTagName("book");
//alert(responseText);
book = books[0];
if (book) {
notification = createRootElement("deneme");
link = book.getAttribute("link");
if (link == document.URL) {
notification.innerHTML = "<p><b>En iyi fiyat :</b> Bu üründe en iyi fiyat bu sitede.</p>";
return;
}
price = book.getAttribute("price");
name = book.getAttribute("name");
store = book.getAttribute("store");
if (store == "1") {
storeName = "İmge.com.tr";
} else if (store == "2") {
storeName = "İdefix.com";
} else if (store == "3") {
storeName = "Kitapyurdu.com";
} else if (store == "4") {
storeName = "Pandora.com.tr";
} else if (store == "5") {
storeName = "Netkitap.com";
} else if (store == "6") {
storeName = "İlknokta.com";
}
notification.innerHTML = "<p>Bu ürünü <b>" + price + " TL</b>'ye <b><a href='" + link + "'>" + storeName + "</a></b> sitesinden alabilirsiniz.</p>";
}
}
//alert(isbn);
chrome.extension.sendRequest({'action' : 'fetchBooks', 'selectedText' : isbn}, showBooks);