2021-01-01 14:27:58 +00:00
|
|
|
/* global $ $$ $create setupLivePrefs */// dom.js
|
|
|
|
/* global ABOUT_BLANK getStyleDataMerged preinit */// preinit.js
|
|
|
|
/* global API msg */// msg.js
|
|
|
|
/* global Events */
|
|
|
|
/* global prefs */
|
|
|
|
/* global t */// localization.js
|
2020-11-18 11:17:15 +00:00
|
|
|
/* global
|
|
|
|
CHROME
|
2021-01-01 14:27:58 +00:00
|
|
|
CHROME_POPUP_BORDER_BUG
|
2020-11-18 11:17:15 +00:00
|
|
|
FIREFOX
|
|
|
|
URLS
|
2021-01-01 14:27:58 +00:00
|
|
|
getActiveTab
|
|
|
|
isEmptyObj
|
|
|
|
*/// toolbox.js
|
2017-03-26 02:30:59 +00:00
|
|
|
'use strict';
|
2017-03-16 13:36:33 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
let tabURL;
|
2021-02-16 14:03:18 +00:00
|
|
|
let isBlocked;
|
2015-01-30 17:28:05 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
/** @type Element */
|
|
|
|
const installed = $('#installed');
|
2017-06-27 20:13:11 +00:00
|
|
|
const ENTRY_ID_PREFIX_RAW = 'style-';
|
2021-01-01 14:27:58 +00:00
|
|
|
const $entry = styleOrId => $(`#${ENTRY_ID_PREFIX_RAW}${styleOrId.id || styleOrId}`);
|
2017-11-14 08:13:03 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
preinit.then(({frames, styles, url}) => {
|
|
|
|
tabURL = url;
|
2020-11-22 19:41:36 +00:00
|
|
|
initPopup(frames);
|
|
|
|
if (styles[0]) {
|
|
|
|
showStyles(styles);
|
|
|
|
} else {
|
|
|
|
// unsupported URL;
|
|
|
|
$('#popup-manage-button').removeAttribute('title');
|
|
|
|
}
|
|
|
|
});
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
msg.onExtension(onRuntimeMessage);
|
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
prefs.subscribe('popup.stylesFirst', (key, stylesFirst) => {
|
2018-11-07 06:09:29 +00:00
|
|
|
const actions = $('body > .actions');
|
|
|
|
const before = stylesFirst ? actions : actions.nextSibling;
|
|
|
|
document.body.insertBefore(installed, before);
|
|
|
|
});
|
2021-01-01 14:27:58 +00:00
|
|
|
if (CHROME_POPUP_BORDER_BUG) {
|
|
|
|
prefs.subscribe('popup.borders', toggleSideBorders, {runNow: true});
|
|
|
|
}
|
|
|
|
if (CHROME >= 66 && CHROME <= 69) { // Chrome 66-69 adds a gap, https://crbug.com/821143
|
|
|
|
document.head.appendChild($create('style', 'html { overflow: overlay }'));
|
2019-09-24 13:21:36 +00:00
|
|
|
}
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2017-04-11 10:51:40 +00:00
|
|
|
function onRuntimeMessage(msg) {
|
2020-10-04 05:30:02 +00:00
|
|
|
if (!tabURL) return;
|
|
|
|
let ready = Promise.resolve();
|
2017-03-31 08:46:18 +00:00
|
|
|
switch (msg.method) {
|
|
|
|
case 'styleAdded':
|
|
|
|
case 'styleUpdated':
|
2018-11-07 06:09:29 +00:00
|
|
|
if (msg.reason === 'editPreview' || msg.reason === 'editPreviewEnd') return;
|
2020-10-04 05:30:02 +00:00
|
|
|
ready = handleUpdate(msg);
|
2017-03-31 08:46:18 +00:00
|
|
|
break;
|
|
|
|
case 'styleDeleted':
|
2018-11-07 06:09:29 +00:00
|
|
|
handleDelete(msg.style.id);
|
2017-03-31 08:46:18 +00:00
|
|
|
break;
|
2017-03-21 01:32:38 +00:00
|
|
|
}
|
2020-10-04 05:30:02 +00:00
|
|
|
ready.then(() => dispatchEvent(new CustomEvent(msg.method, {detail: msg})));
|
2017-04-11 10:51:40 +00:00
|
|
|
}
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
function setPopupWidth(_key, width) {
|
2017-04-04 17:21:03 +00:00
|
|
|
document.body.style.width =
|
|
|
|
Math.max(200, Math.min(800, width)) + 'px';
|
|
|
|
}
|
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
function toggleSideBorders(_key, state) {
|
2017-11-14 08:13:03 +00:00
|
|
|
// runs before <body> is parsed
|
|
|
|
const style = document.documentElement.style;
|
2021-01-01 14:27:58 +00:00
|
|
|
if (state) {
|
2017-11-14 08:13:03 +00:00
|
|
|
style.cssText +=
|
|
|
|
'border-left: 2px solid white !important;' +
|
|
|
|
'border-right: 2px solid white !important;';
|
|
|
|
} else if (style.cssText) {
|
|
|
|
style.borderLeft = style.borderRight = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
/** @param {chrome.webNavigation.GetAllFrameResultDetails[]} frames */
|
2020-11-22 11:09:59 +00:00
|
|
|
async function initPopup(frames) {
|
2021-01-01 14:27:58 +00:00
|
|
|
prefs.subscribe('popupWidth', setPopupWidth, {runNow: true});
|
2015-03-12 23:00:23 +00:00
|
|
|
|
2017-03-21 01:32:38 +00:00
|
|
|
// action buttons
|
2017-07-16 16:49:31 +00:00
|
|
|
$('#disableAll').onchange = function () {
|
2017-04-11 11:22:00 +00:00
|
|
|
installed.classList.toggle('disabled', this.checked);
|
|
|
|
};
|
2017-04-21 16:39:34 +00:00
|
|
|
setupLivePrefs();
|
2017-04-09 06:43:51 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
Object.assign($('#find-styles-link'), {
|
|
|
|
href: URLS.usoArchive,
|
|
|
|
async onclick(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
await require(['/popup/search']);
|
|
|
|
Events.searchOnClick(this, e);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-08-22 16:29:26 +00:00
|
|
|
Object.assign($('#popup-manage-button'), {
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: Events.openManager,
|
|
|
|
oncontextmenu: Events.openManager,
|
2017-08-22 16:29:26 +00:00
|
|
|
});
|
2017-04-09 06:43:51 +00:00
|
|
|
|
|
|
|
$('#popup-options-button').onclick = () => {
|
2020-02-02 04:36:54 +00:00
|
|
|
API.openManage({options: true});
|
2017-04-09 06:43:51 +00:00
|
|
|
window.close();
|
|
|
|
};
|
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('#popup-wiki-button').onclick = Events.openURLandHide;
|
2018-04-12 18:02:34 +00:00
|
|
|
|
2020-11-23 09:09:30 +00:00
|
|
|
$('#confirm').onclick = function (e) {
|
|
|
|
const {id} = this.dataset;
|
|
|
|
switch (e.target.dataset.cmd) {
|
|
|
|
case 'ok':
|
2021-01-01 14:27:58 +00:00
|
|
|
Events.hideModal(this, {animate: true});
|
|
|
|
API.styles.delete(Number(id));
|
2020-11-23 09:09:30 +00:00
|
|
|
break;
|
|
|
|
case 'cancel':
|
2021-01-01 14:27:58 +00:00
|
|
|
Events.showModal($('.menu', $entry(id)), '.menu-close');
|
2020-11-23 09:09:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-21 01:32:38 +00:00
|
|
|
if (!prefs.get('popup.stylesFirst')) {
|
|
|
|
document.body.insertBefore(
|
|
|
|
$('body > .actions'),
|
|
|
|
installed);
|
|
|
|
}
|
|
|
|
|
2020-11-22 19:41:36 +00:00
|
|
|
for (const el of $$('link[media=print]')) {
|
|
|
|
el.removeAttribute('media');
|
|
|
|
}
|
|
|
|
|
2018-01-01 17:02:49 +00:00
|
|
|
if (!tabURL) {
|
2020-10-04 05:30:02 +00:00
|
|
|
blockPopup();
|
2017-03-21 01:32:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
frames.forEach(createWriterElement);
|
|
|
|
if (frames.length > 1) {
|
|
|
|
const el = $('#write-for-frames');
|
|
|
|
el.hidden = false;
|
|
|
|
el.onclick = () => el.classList.toggle('expanded');
|
|
|
|
}
|
|
|
|
|
2020-11-22 11:09:59 +00:00
|
|
|
const isStore = tabURL.startsWith(URLS.browserWebStore);
|
|
|
|
if (isStore && !FIREFOX) {
|
|
|
|
blockPopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let retryCountdown = 10; retryCountdown-- > 0;) {
|
|
|
|
const tab = await getActiveTab();
|
|
|
|
if (await msg.sendTab(tab.id, {method: 'ping'}, {frameId: 0}).catch(() => {})) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tab.status === 'complete' && (!FIREFOX || tab.url !== ABOUT_BLANK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FF and some Chrome forks (e.g. CentBrowser) implement tab-on-demand
|
|
|
|
// so we'll wait a bit to handle popup being invoked right after switching
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
}
|
2020-11-22 19:41:36 +00:00
|
|
|
|
|
|
|
initUnreachable(isStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
function initUnreachable(isStore) {
|
2020-11-22 11:09:59 +00:00
|
|
|
const info = t.template.unreachableInfo;
|
|
|
|
if (!FIREFOX) {
|
|
|
|
// Chrome "Allow access to file URLs" in chrome://extensions message
|
|
|
|
info.appendChild($create('p', t('unreachableFileHint')));
|
2021-03-12 05:25:35 +00:00
|
|
|
} else {
|
2020-11-22 11:09:59 +00:00
|
|
|
$('label', info).textContent = t('unreachableAMO');
|
2021-03-12 05:25:35 +00:00
|
|
|
const note = [
|
|
|
|
isStore && t(FIREFOX >= 59 ? 'unreachableAMOHint' : 'unreachableMozSiteHintOldFF'),
|
|
|
|
FIREFOX >= 60 && t('unreachableMozSiteHint'),
|
|
|
|
].filter(Boolean).join('\n');
|
2020-11-22 11:09:59 +00:00
|
|
|
const renderToken = s => s[0] === '<'
|
2021-03-12 05:25:35 +00:00
|
|
|
? $create('button.fake.copy', {
|
2020-11-22 11:09:59 +00:00
|
|
|
textContent: s.slice(1, -1),
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: Events.copyContent,
|
2020-11-22 11:09:59 +00:00
|
|
|
title: t('copy'),
|
|
|
|
})
|
|
|
|
: s;
|
|
|
|
const renderLine = line => $create('p', line.split(/(<.*?>)/).map(renderToken));
|
|
|
|
const noteNode = $create('fragment', note.split('\n').map(renderLine));
|
|
|
|
info.appendChild(noteNode);
|
|
|
|
}
|
|
|
|
// Inaccessible locally hosted file type, e.g. JSON, PDF, etc.
|
|
|
|
if (tabURL.length - tabURL.lastIndexOf('.') <= 5) {
|
|
|
|
info.appendChild($create('p', t('InaccessibleFileHint')));
|
|
|
|
}
|
|
|
|
document.body.classList.add('unreachable');
|
|
|
|
document.body.insertBefore(info, document.body.firstChild);
|
2020-02-24 23:16:45 +00:00
|
|
|
}
|
2017-04-12 09:57:40 +00:00
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
/** @param {chrome.webNavigation.GetAllFrameResultDetails} frame */
|
|
|
|
function createWriterElement(frame) {
|
|
|
|
const {url, frameId, parentFrameId, isDupe} = frame;
|
|
|
|
const targets = $create('span');
|
2017-03-21 01:32:38 +00:00
|
|
|
|
|
|
|
// For this URL
|
2020-11-18 11:17:15 +00:00
|
|
|
const urlLink = t.template.writeStyle.cloneNode(true);
|
2020-02-24 23:16:45 +00:00
|
|
|
const isAboutBlank = url === ABOUT_BLANK;
|
2017-03-21 01:32:38 +00:00
|
|
|
Object.assign(urlLink, {
|
2020-02-24 23:16:45 +00:00
|
|
|
href: 'edit.html?url-prefix=' + encodeURIComponent(url),
|
|
|
|
title: `url-prefix("${url}")`,
|
|
|
|
tabIndex: isAboutBlank ? -1 : 0,
|
2017-03-21 01:32:38 +00:00
|
|
|
textContent: prefs.get('popup.breadcrumbs.usePath')
|
2020-02-24 23:16:45 +00:00
|
|
|
? new URL(url).pathname.slice(1)
|
|
|
|
: frameId
|
|
|
|
? isAboutBlank ? url : 'URL'
|
|
|
|
: t('writeStyleForURL').replace(/ /g, '\u00a0'), // this URL
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: e => Events.openEditor(e, {'url-prefix': url}),
|
2017-03-21 01:32:38 +00:00
|
|
|
});
|
|
|
|
if (prefs.get('popup.breadcrumbs')) {
|
|
|
|
urlLink.onmouseenter =
|
|
|
|
urlLink.onfocus = () => urlLink.parentNode.classList.add('url()');
|
|
|
|
urlLink.onmouseleave =
|
|
|
|
urlLink.onblur = () => urlLink.parentNode.classList.remove('url()');
|
|
|
|
}
|
2020-02-24 23:16:45 +00:00
|
|
|
targets.appendChild(urlLink);
|
2017-03-21 01:32:38 +00:00
|
|
|
|
|
|
|
// For domain
|
2020-02-24 23:16:45 +00:00
|
|
|
const domains = getDomains(url);
|
2017-03-26 02:30:59 +00:00
|
|
|
for (const domain of domains) {
|
2017-08-14 18:15:29 +00:00
|
|
|
const numParts = domain.length - domain.replace(/\./g, '').length + 1;
|
2017-03-21 01:32:38 +00:00
|
|
|
// Don't include TLD
|
2017-08-14 18:15:29 +00:00
|
|
|
if (domains.length > 1 && numParts === 1) {
|
2017-03-21 01:32:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-11-18 11:17:15 +00:00
|
|
|
const domainLink = t.template.writeStyle.cloneNode(true);
|
2017-03-21 01:32:38 +00:00
|
|
|
Object.assign(domainLink, {
|
|
|
|
href: 'edit.html?domain=' + encodeURIComponent(domain),
|
2017-08-14 18:15:29 +00:00
|
|
|
textContent: numParts > 2 ? domain.split('.')[0] : domain,
|
2017-03-21 01:32:38 +00:00
|
|
|
title: `domain("${domain}")`,
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: e => Events.openEditor(e, {domain}),
|
2017-03-21 01:32:38 +00:00
|
|
|
});
|
2017-08-14 18:15:29 +00:00
|
|
|
domainLink.setAttribute('subdomain', numParts > 1 ? 'true' : '');
|
2020-02-24 23:16:45 +00:00
|
|
|
targets.appendChild(domainLink);
|
2017-03-21 01:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prefs.get('popup.breadcrumbs')) {
|
2020-02-24 23:16:45 +00:00
|
|
|
targets.classList.add('breadcrumbs');
|
|
|
|
targets.appendChild(urlLink); // making it the last element
|
2017-03-21 01:32:38 +00:00
|
|
|
}
|
2018-01-01 17:02:49 +00:00
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
const root = $('#write-style');
|
|
|
|
const parent = $(`[data-frame-id="${parentFrameId}"]`, root) || root;
|
|
|
|
const child = $create({
|
|
|
|
tag: 'span',
|
|
|
|
className: `match${isDupe ? ' dupe' : ''}${isAboutBlank ? ' about-blank' : ''}`,
|
|
|
|
dataset: {frameId},
|
|
|
|
appendChild: targets,
|
|
|
|
});
|
|
|
|
parent.appendChild(child);
|
|
|
|
parent.dataset.children = (Number(parent.dataset.children) || 0) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDomains(url) {
|
|
|
|
let d = url.split(/[/:]+/, 2)[1];
|
|
|
|
if (!d || url.startsWith('file:')) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
const domains = [d];
|
|
|
|
while (d.includes('.')) {
|
|
|
|
d = d.substring(d.indexOf('.') + 1);
|
|
|
|
domains.push(d);
|
2018-01-01 17:02:49 +00:00
|
|
|
}
|
2020-02-24 23:16:45 +00:00
|
|
|
return domains;
|
2015-03-23 18:56:11 +00:00
|
|
|
}
|
2012-08-20 01:14:33 +00:00
|
|
|
|
2019-01-01 05:11:45 +00:00
|
|
|
function sortStyles(entries) {
|
|
|
|
const enabledFirst = prefs.get('popup.enabledFirst');
|
2020-02-24 23:16:45 +00:00
|
|
|
return entries.sort(({styleMeta: a}, {styleMeta: b}) =>
|
|
|
|
Boolean(a.frameUrl) - Boolean(b.frameUrl) ||
|
|
|
|
enabledFirst && Boolean(b.enabled) - Boolean(a.enabled) ||
|
2020-10-11 15:12:06 +00:00
|
|
|
(a.customName || a.name).localeCompare(b.customName || b.name));
|
2019-01-01 05:11:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
function showStyles(frameResults) {
|
|
|
|
const entries = new Map();
|
|
|
|
frameResults.forEach(({styles = [], url}, index) => {
|
2021-02-16 14:03:18 +00:00
|
|
|
if (isBlocked && !index) return;
|
2020-02-24 23:16:45 +00:00
|
|
|
styles.forEach(style => {
|
2020-10-04 05:30:02 +00:00
|
|
|
const {id} = style;
|
2020-02-24 23:16:45 +00:00
|
|
|
if (!entries.has(id)) {
|
|
|
|
style.frameUrl = index === 0 ? '' : url;
|
2020-10-04 05:30:02 +00:00
|
|
|
entries.set(id, createStyleElement(style));
|
2020-02-24 23:16:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (entries.size) {
|
2020-10-04 05:30:02 +00:00
|
|
|
resortEntries([...entries.values()]);
|
2020-02-24 23:16:45 +00:00
|
|
|
} else {
|
2020-11-18 11:17:15 +00:00
|
|
|
installed.appendChild(t.template.noStyles);
|
2017-03-30 23:18:41 +00:00
|
|
|
}
|
2021-01-01 14:27:58 +00:00
|
|
|
require(['/popup/hotkeys']);
|
2012-08-20 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 05:30:02 +00:00
|
|
|
function resortEntries(entries) {
|
|
|
|
// `entries` is specified only at startup, after that we respect the prefs
|
|
|
|
if (entries || prefs.get('popup.autoResort')) {
|
|
|
|
installed.append(...sortStyles(entries || $$('.entry', installed)));
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2019-01-01 05:11:45 +00:00
|
|
|
function createStyleElement(style) {
|
2021-01-01 14:27:58 +00:00
|
|
|
let entry = $entry(style);
|
2018-11-07 06:09:29 +00:00
|
|
|
if (!entry) {
|
2020-11-18 11:17:15 +00:00
|
|
|
entry = t.template.style.cloneNode(true);
|
2018-11-07 06:09:29 +00:00
|
|
|
Object.assign(entry, {
|
|
|
|
id: ENTRY_ID_PREFIX_RAW + style.id,
|
|
|
|
styleId: style.id,
|
|
|
|
styleIsUsercss: Boolean(style.usercssData),
|
2021-01-01 14:27:58 +00:00
|
|
|
onmousedown: Events.maybeEdit,
|
2020-11-18 11:17:15 +00:00
|
|
|
styleMeta: style,
|
2018-11-07 06:09:29 +00:00
|
|
|
});
|
2020-11-20 14:00:20 +00:00
|
|
|
Object.assign($('input', entry), {
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: Events.toggleState,
|
2018-11-07 06:09:29 +00:00
|
|
|
});
|
2021-02-27 17:42:49 +00:00
|
|
|
Object.assign($('.style-edit-link', entry), {
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: e => Events.openEditor(e, {id: style.id}),
|
2018-11-07 06:09:29 +00:00
|
|
|
});
|
|
|
|
const styleName = $('.style-name', entry);
|
|
|
|
Object.assign(styleName, {
|
|
|
|
htmlFor: ENTRY_ID_PREFIX_RAW + style.id,
|
2021-01-01 14:27:58 +00:00
|
|
|
onclick: Events.name,
|
2018-11-07 06:09:29 +00:00
|
|
|
});
|
|
|
|
styleName.appendChild(document.createTextNode(' '));
|
2018-12-10 13:57:44 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
const config = $('.configure', entry);
|
2021-01-01 14:27:58 +00:00
|
|
|
config.onclick = Events.configure;
|
2018-12-10 13:57:44 +00:00
|
|
|
if (!style.usercssData) {
|
|
|
|
if (style.updateUrl && style.updateUrl.includes('?') && style.url) {
|
|
|
|
config.href = style.url;
|
|
|
|
config.target = '_blank';
|
|
|
|
config.title = t('configureStyleOnHomepage');
|
2021-02-27 17:42:49 +00:00
|
|
|
config._sendMessage = {method: 'openSettings'};
|
2018-12-10 13:57:44 +00:00
|
|
|
$('use', config).attributes['xlink:href'].nodeValue = '#svg-icon-config-uso';
|
|
|
|
} else {
|
|
|
|
config.classList.add('hidden');
|
|
|
|
}
|
2021-01-01 14:27:58 +00:00
|
|
|
} else if (isEmptyObj(style.usercssData.vars)) {
|
2018-12-10 13:57:44 +00:00
|
|
|
config.classList.add('hidden');
|
2018-11-07 06:09:29 +00:00
|
|
|
}
|
2018-12-10 13:57:44 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('.delete', entry).onclick = Events.delete;
|
2018-11-07 06:09:29 +00:00
|
|
|
|
2020-11-18 11:17:15 +00:00
|
|
|
const indicator = t.template.regexpProblemIndicator.cloneNode(true);
|
2018-11-07 06:09:29 +00:00
|
|
|
indicator.appendChild(document.createTextNode('!'));
|
2021-01-01 14:27:58 +00:00
|
|
|
indicator.onclick = Events.indicator;
|
2018-11-07 06:09:29 +00:00
|
|
|
$('.main-controls', entry).appendChild(indicator);
|
2019-03-03 22:54:37 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('.menu-button', entry).onclick = Events.toggleMenu;
|
|
|
|
$('.menu-close', entry).onclick = Events.toggleMenu;
|
2019-03-03 22:54:37 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('.exclude-by-domain-checkbox', entry).onchange = e => Events.toggleExclude(e, 'domain');
|
|
|
|
$('.exclude-by-url-checkbox', entry).onchange = e => Events.toggleExclude(e, 'url');
|
2018-11-07 06:09:29 +00:00
|
|
|
}
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
style = Object.assign(entry.styleMeta, style);
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
entry.classList.toggle('disabled', !style.enabled);
|
|
|
|
entry.classList.toggle('enabled', style.enabled);
|
2020-11-20 14:00:20 +00:00
|
|
|
$('input', entry).checked = style.enabled;
|
2017-03-21 01:32:38 +00:00
|
|
|
|
|
|
|
const styleName = $('.style-name', entry);
|
2020-10-11 15:12:06 +00:00
|
|
|
styleName.lastChild.textContent = style.customName || style.name;
|
2018-11-07 06:09:29 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
styleName.title = entry.styleMeta.sloppy ?
|
|
|
|
t('styleNotAppliedRegexpProblemTooltip') :
|
|
|
|
styleName.scrollWidth > styleName.clientWidth + 1 ?
|
|
|
|
styleName.textContent : '';
|
2017-11-26 12:31:00 +00:00
|
|
|
});
|
2017-03-21 01:32:38 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
entry.classList.toggle('not-applied', style.excluded || style.sloppy);
|
|
|
|
entry.classList.toggle('regexp-partial', style.sloppy);
|
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('.exclude-by-domain-checkbox', entry).checked = Events.isStyleExcluded(style, 'domain');
|
|
|
|
$('.exclude-by-url-checkbox', entry).checked = Events.isStyleExcluded(style, 'url');
|
2019-03-03 22:54:37 +00:00
|
|
|
|
2021-01-01 14:27:58 +00:00
|
|
|
$('.exclude-by-domain', entry).title = Events.getExcludeRule('domain');
|
|
|
|
$('.exclude-by-url', entry).title = Events.getExcludeRule('url');
|
2019-03-03 22:54:37 +00:00
|
|
|
|
2020-02-24 23:16:45 +00:00
|
|
|
const {frameUrl} = style;
|
|
|
|
if (frameUrl) {
|
|
|
|
const sel = 'span.frame-url';
|
|
|
|
const frameEl = $(sel, entry) || styleName.insertBefore($create(sel), styleName.lastChild);
|
|
|
|
frameEl.title = frameUrl;
|
2021-01-01 14:27:58 +00:00
|
|
|
frameEl.onmousedown = Events.maybeEdit;
|
2020-02-24 23:16:45 +00:00
|
|
|
}
|
|
|
|
entry.classList.toggle('frame', Boolean(frameUrl));
|
|
|
|
|
2019-01-01 05:11:45 +00:00
|
|
|
return entry;
|
2012-08-20 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 05:30:02 +00:00
|
|
|
async function handleUpdate({style, reason}) {
|
2021-01-01 14:27:58 +00:00
|
|
|
if (reason !== 'toggle' || !$entry(style)) {
|
2020-10-04 05:30:02 +00:00
|
|
|
style = await getStyleDataMerged(tabURL, style.id);
|
|
|
|
if (!style) return;
|
|
|
|
}
|
|
|
|
const el = createStyleElement(style);
|
|
|
|
if (!el.parentNode) {
|
|
|
|
installed.appendChild(el);
|
|
|
|
blockPopup(false);
|
2018-11-07 06:09:29 +00:00
|
|
|
}
|
2020-10-04 05:30:02 +00:00
|
|
|
resortEntries();
|
2012-08-20 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleDelete(id) {
|
2021-01-01 14:27:58 +00:00
|
|
|
const el = $entry(id);
|
2020-10-04 05:30:02 +00:00
|
|
|
if (el) {
|
|
|
|
el.remove();
|
2020-11-18 11:17:15 +00:00
|
|
|
if (!$('.entry')) installed.appendChild(t.template.noStyles);
|
2017-12-12 02:21:06 +00:00
|
|
|
}
|
2017-03-30 23:18:41 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 14:03:18 +00:00
|
|
|
function blockPopup(val = true) {
|
|
|
|
isBlocked = val;
|
2020-10-04 05:30:02 +00:00
|
|
|
document.body.classList.toggle('blocked', isBlocked);
|
|
|
|
if (isBlocked) {
|
2020-11-18 11:17:15 +00:00
|
|
|
document.body.prepend(t.template.unavailableInfo);
|
2020-10-04 05:30:02 +00:00
|
|
|
} else {
|
2020-11-18 11:17:15 +00:00
|
|
|
t.template.unavailableInfo.remove();
|
|
|
|
t.template.noStyles.remove();
|
2020-10-04 05:30:02 +00:00
|
|
|
}
|
|
|
|
}
|