-
Notifications
You must be signed in to change notification settings - Fork 2
/
hamichlol.js
55 lines (42 loc) · 1.31 KB
/
hamichlol.js
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
var pageTitle = $("#firstHeading").text().trim();
function CheckIfLinksfromWikipedia() {
$("#mw-content-text a.new").each(function () {
var a = this;
var $this = $(a);
var href = $this.attr('href');
if (!href) return;
var title = false;
try {
title = (new URL(href, window.location.origin)).searchParams.get('title');
} catch (e) { };
if (!title) return;
if (title.indexOf(":") != -1) return;
if(a._checkWikipedia) return;
a._checkWikipedia = true;
chrome.extension.sendRequest({ func: "ifHaveWikipedia", title: title }, function (response) {
if (response.have) {
var $a = $("<a>")
.attr("href","https://he.wikipedia.org/wiki/" + encodeURIComponent(title) )
.attr("target","_blank")
.text("W")
.addClass("ex-michlol-link-wiki");
$this.after($a);
}
});
});
};
chrome.extension.sendRequest({ func: "getOptions" }, function (response) {
if (response.options.markPageInWikipedia) {
$(CheckIfLinksfromWikipedia);
}
if (response.options.showWikipediaCompare){
var $but = $("<button>");
$but
.text("השווה מול ויקיפדיה")
.addClass('ex-michlol-button')
.appendTo($("#firstHeading"))
.on('click', () => {
chrome.extension.sendRequest({ func: "compareWikipedia", title: pageTitle }, function (response) { });
});
}
});