-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
155 lines (128 loc) · 5.11 KB
/
popup.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Created by Mardan MEMET ([email protected]) on 28/11/2017.
* GNU General Public License v3.0
*/
tq = {
fonts: [
{ "name": "تۈز", "value": "UKIJ Tuz", "file": "UKIJTuz.ttf" },
{ "name": "تۈز تور", "value": "UKIJ Tuz Tor", "file": "UKIJTzTr.ttf" },
{ "name": "تۈز باسما", "value": "UKIJ Tuz Basma", "file": "UKIJTuzB.ttf" },
{ "name": "تۈز كىتاب", "value": "UKIJ Tuz Kitab", "file": "UKIJTuzK.ttf" },
{ "name": "تۈز قارا", "value": "UKIJ Tuz Qara", "file": "UKIJTuzQ.ttf" },
{ "name": "ئېكران", "value": "UKIJ Ekran", "file": "UKIJEkran.ttf" },
{ "name": "باسما", "value": "UKIJ Basma", "file": "UKIJBasma.ttf" },
{ "name": "زىلۋا", "value": "UKIJ Zilwa", "file": "UKIJZilwa.ttf" }
],
fontSelectedIndex: null,
init: function () {
tq.mouseSelect();
tq.setPage();
tq.bindEvents();
},
setPage: function () {
tq.fonts.forEach(function (element, index) {
var option = '<li style="font-family: '+element.value+'; text-align: right;cursor: pointer;"><a id="font-select-'+index+'">'+element.name+'</a></li>';
$('#fontStyle').append(option);
var select = $('#font-select-'+index);
select.on('click', function () {
tq.setFontStyle(tq.fonts[index]);
})
});
},
mouseSelect: function() {
var params = tq.getGlobalSelect();
if (params.mouseSelect) {
chrome.tabs.executeScript(null, {
file: 'js/selector.js'
});
}
},
bindEvents: function() {
// UY -> ULY convert
$('#uytouly').on('click', function () {
chrome.tabs.executeScript(null, {
file: 'js/uy2uly.js'
});
});
// ULY -> UY convert event
$('#ulytouy').on('click', function () {
chrome.tabs.executeScript(null, {
file: 'js/uly2uy.js'
});
});
// font size
var fontSize = $('#fontSize');
var fontSizeCounter = $('#fontSizeCounter');
fontSize.on('input', function () {
var size = this.value;
fontSizeCounter.text(size);
tq.setFontSize(size);
});
// text direction
$('#direction').change(function () {
if (this.checked) {
tq.setDirection('rtl');
} else {
tq.setDirection('');
}
});
// font color
$('#fontColor').on('input', function () {
color = this.value;
tq.setFontColor(color);
});
// background color
$('#bgColor').on('input', function () {
color = this.value;
tq.setBackgroundColor(color);
});
// refresh page
$('#refresh').on('click', function () {
chrome.tabs.executeScript(null, {code: "window.location.reload();"});
});
},
setFontStyle: function(font) {
var code = tq.setStyle('fontFamily', font.value);
code+= tq.setHeadStyle(font.value, font.file);
chrome.tabs.executeScript(null,{code:code});
},
setFontSize: function(size) {
var code = tq.setStyle('fontSize', size+'px');
chrome.tabs.executeScript(null,{code:code});
},
setDirection: function(direction) {
var code = tq.setStyle('direction', direction);
chrome.tabs.executeScript(null,{code:code});
},
setFontColor: function(color) {
var code = tq.setStyle('color', color);
chrome.tabs.executeScript(null,{code:code});
},
setBackgroundColor: function(color) {
var code = tq.setStyle('backgroundColor', color);
chrome.tabs.executeScript(null,{code:code});
},
setStyle: function(style, value) {
var params = tq.getGlobalSelect();
if (params.globalSelect) {
return "var es=document.body.getElementsByTagName('*');for(var i=0;i<es.length;i++){var search=es[i].innerText;if(es[i]['tagName'] !='SCRIPT'){es[i].style."+style+"='"+value+"';}}";
}
return "var regex=/[\u0600-\u06FF]/;var es=document.body.getElementsByTagName('*');for(var i=0;i<es.length;i++){var search=es[i].innerText;if(es[i]['tagName'] !='SCRIPT' && regex.test(search)){es[i].style."+style+"='"+value+"';}}";
},
setHeadStyle: function(fontName, fileName) {
var file = "chrome-extension://feekbgjlnbmihodgdomphfgiakdkfbfo/fonts/"+fileName;
return 'var css="@font-face {font-family: '+fontName+';src: url('+file+');}";'+
'var head = document.head;var style = document.createElement("style");'+
'if(style.styleSheet) {style.styleSheet.cssText=css;}else{style.appendChild(document.createTextNode(css));}head.appendChild(style);';
},
isUy: function (text) {
var regex = /[\u0600-\u06FF]/;
return regex.test(text);
},
getGlobalSelect: function() {
var param = localStorage.getItem("params");
if (param === null) return false;
return JSON.parse(param);
}
};
$(tq.init);