Skip to content

Commit d064b3c

Browse files
committed
css part
load css only if monkey is at home exclude datepicker from font settings so as not to break the width
1 parent 3327af9 commit d064b3c

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"update.popup.js",
3434
"processTree.popup.js",
3535
"script.js"],
36-
"css": ["siemMonkey.css","libs/jquery-ui-1.12.1/jquery-ui.min.monkey.css"],
3736
"all_frames": true
3837
}
3938
],
@@ -45,7 +44,7 @@
4544
{
4645
"resources": [
4746
"img/icon128.png",
48-
"siemMonkey.css",
47+
"siemMonkey.css",
4948
"customfilters.json",
5049
"fieldaliases.json",
5150
"xhr_override.js",

popup.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ body.loading .lds-dual-ring {
2626
display: block;
2727
}
2828

29-
* { font-family:Roboto,Helvetica Neue,sans-serif; font-size:10px; }
29+
:not([class^="ui-datepicker"]) {
30+
font-family: Roboto,Helvetica Neue,sans-serif;
31+
font-size: 10px;
32+
}
3033

3134
.parent {
3235
color: white;

script.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ function SearchBananas (selectors, callback, interval, timeout) {
125125
}, interval);
126126
};
127127

128+
/**
129+
* Adopting a constructed stylesheet to be used by the document or ShadowRoots
130+
* @param {*} doc document or ShadowRoot to adopt
131+
* @param {*} path CSS file path
132+
*/
133+
function adoptCSS(doc, path) {
134+
let MonkeyCSS;
135+
try {
136+
let css_url = chrome.runtime.getURL(path);
137+
let xhr = new XMLHttpRequest();
138+
xhr.onload = function () {
139+
MonkeyCSS = this.response;
140+
};
141+
xhr.open("GET", css_url, false);
142+
xhr.send();
143+
} catch (err) {
144+
console.log("Не удалось прочитать файл " + path);
145+
return;
146+
}
147+
const sheet = new CSSStyleSheet();
148+
sheet.replaceSync(MonkeyCSS);
149+
doc.adoptedStyleSheets = [sheet];
150+
}
151+
128152
function siemMonkeyBind(product) {
129153
// Let's set locale and string formats for date/time conversions
130154
// TODO: add custom locale format to options
@@ -146,6 +170,18 @@ function siemMonkeyBind(product) {
146170
insertMonkeyIntoUI(product);
147171
}
148172

173+
// load CSS in main tree
174+
let ui_css_path = chrome.runtime.getURL("libs/jquery-ui-1.12.1/jquery-ui.min.monkey.css");
175+
let ui_css_path2 = chrome.runtime.getURL("siemMonkey.css");
176+
$('head').append($('<link>')
177+
.attr("rel","stylesheet")
178+
.attr("type","text/css")
179+
.attr("href", ui_css_path));
180+
$('head').append($('<link>')
181+
.attr("rel","stylesheet")
182+
.attr("type","text/css")
183+
.attr("href", ui_css_path2));
184+
149185
// Если есть элементы "legacy-overlay" и "legacy-events-page", то мы очутились в 26.1
150186
// Загружать CSS и вешать обработчик мутаций страницы нужно внутри shadowRoot
151187
let legacy_overlay = $("legacy-overlay");
@@ -157,27 +193,7 @@ function siemMonkeyBind(product) {
157193
characterData: true,
158194
attributes: true,
159195
});
160-
let jquery_ui_css;
161-
try {
162-
let css_url = chrome.runtime.getURL(
163-
"libs/jquery-ui-1.12.1/jquery-ui.min.monkey.css" // using jquery-ui css just with embedded images
164-
);
165-
let xhr = new XMLHttpRequest();
166-
xhr.onload = function () {
167-
jquery_ui_css = this.response;
168-
};
169-
xhr.open("GET", css_url, false);
170-
xhr.send();
171-
} catch (err) {
172-
console.log(
173-
"Не удалось прочитать файл libs/jquery-ui-1.12.1/jquery-ui.min.monkey.css"
174-
);
175-
return;
176-
}
177-
178-
const sheet = new CSSStyleSheet();
179-
sheet.replaceSync(jquery_ui_css);
180-
shadowRoot.adoptedStyleSheets = [sheet];
196+
adoptCSS(shadowRoot, "libs/jquery-ui-1.12.1/jquery-ui.min.monkey.css"); // using jquery-ui css just with embedded images
181197
}
182198

183199
let legacy_events_page = $("legacy-events-page");
@@ -189,26 +205,10 @@ function siemMonkeyBind(product) {
189205
characterData: true,
190206
attributes: true,
191207
});
192-
let siemMonkeyCSS;
193-
try {
194-
let css_url = chrome.runtime.getURL("siemMonkey.css");
195-
let xhr = new XMLHttpRequest();
196-
xhr.onload = function () {
197-
siemMonkeyCSS = this.response;
198-
};
199-
xhr.open("GET", css_url, false);
200-
xhr.send();
201-
} catch (err) {
202-
console.log("Не удалось прочитать файл siemMonkey.css");
203-
return;
204-
}
205-
206-
const sheet = new CSSStyleSheet();
207-
sheet.replaceSync(siemMonkeyCSS);
208-
shadowRoot.adoptedStyleSheets = [sheet];
208+
adoptCSS(shadowRoot, "siemMonkey.css");
209209
} else {
210210
// Старый добрый UI до 26.0 включительно - вешаем обработчик мутаций прямо на весь document,
211-
// а CSSы уже и так загружены расширением
211+
// CSS уже подгружен
212212
observer.observe(document, {
213213
childList: true,
214214
subtree: true,

0 commit comments

Comments
 (0)