WIP: kill cachedStyles

This commit is contained in:
eight 2018-10-11 00:54:38 +08:00
parent 7eba890a21
commit ba64b95575
42 changed files with 188 additions and 222 deletions

View File

@ -475,3 +475,15 @@ function updateAllTabsIcon() {
tabs.map(t => updateIcon({tab: t})) tabs.map(t => updateIcon({tab: t}))
); );
} }
function openEditor({id}) {
let url = '/edit.html';
if (id) {
url += `?id=${id}`;
}
if (chrome.windows && prefs.get('openEditInWindow')) {
chrome.windows.create(Object.assign({url}, prefs.get('windowPosition')));
} else {
openURL({url});
}
}

View File

@ -1,6 +1,7 @@
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */ /* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
/* global createCache db calcStyleDigest normalizeStyleSections db promisify /* global createCache db calcStyleDigest db tryRegExp
getStyleWithNoCode msg */ getStyleWithNoCode msg */
/* exported styleManager */
'use strict'; 'use strict';
/* /*

View File

@ -1,4 +1,4 @@
/* global getStyles API_METHODS styleManager */ /* global API_METHODS styleManager CHROME prefs */
'use strict'; 'use strict';
API_METHODS.styleViaAPI = !CHROME && (() => { API_METHODS.styleViaAPI = !CHROME && (() => {

View File

@ -1,9 +1,7 @@
/* /* global styleSectionsEqual prefs download tryJSONparse ignoreChromeError
global styleSectionsEqual calcStyleDigest getStyleWithNoCode debounce chromeLocal
global calcStyleDigest cachedStyles getStyleWithNoCode usercss semverCompare
global usercss semverCompare API_METHODS styleManager */
global API_METHODS styleManager
*/
'use strict'; 'use strict';
(() => { (() => {
@ -70,7 +68,7 @@ global API_METHODS styleManager
function checkStyle({ function checkStyle({
id, id,
style = cachedStyles.byId.get(id), style,
port, port,
save = true, save = true,
ignoreDigest, ignoreDigest,
@ -89,7 +87,7 @@ global API_METHODS styleManager
'ignoreDigest' option is set on the second manual individual update check on the manage page. 'ignoreDigest' option is set on the second manual individual update check on the manage page.
*/ */
return Promise.resolve(style) return fetchStyle()
.then([calcStyleDigest][!ignoreDigest ? 0 : 'skip']) .then([calcStyleDigest][!ignoreDigest ? 0 : 'skip'])
.then([checkIfEdited][!ignoreDigest ? 0 : 'skip']) .then([checkIfEdited][!ignoreDigest ? 0 : 'skip'])
.then([maybeUpdateUSO, maybeUpdateUsercss][style.usercssData ? 1 : 0]) .then([maybeUpdateUSO, maybeUpdateUsercss][style.usercssData ? 1 : 0])
@ -97,6 +95,16 @@ global API_METHODS styleManager
.then(reportSuccess) .then(reportSuccess)
.catch(reportFailure); .catch(reportFailure);
function fetchStyle() {
if (style) {
return Promise.resolve();
}
return styleManager.get(id)
.then(_style => {
style = _style;
});
}
function reportSuccess(saved) { function reportSuccess(saved) {
log(STATES.UPDATED + ` #${style.id} ${style.name}`); log(STATES.UPDATED + ` #${style.id} ${style.name}`);
const info = {updated: true, style: saved}; const info = {updated: true, style: saved};

View File

@ -1,4 +1,5 @@
/* global API_METHODS usercss chromeLocal styleManager */ /* global API_METHODS usercss chromeLocal styleManager FIREFOX deepCopy openURL
download */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,5 +1,5 @@
/* eslint no-var: 0 */ /* eslint no-var: 0 */
/* global msg */ /* global msg API prefs */
'use strict'; 'use strict';
(() => { (() => {
@ -79,18 +79,18 @@
* @param {Function} callback * @param {Function} callback
* @returns {Boolean|undefined} * @returns {Boolean|undefined}
*/ */
function getStylesFallback(msg) { // function getStylesFallback(msg) {
if (window !== parent && // if (window !== parent &&
location.href !== 'about:blank') { // location.href !== 'about:blank') {
try { // try {
if (parent.location.origin === location.origin && // if (parent.location.origin === location.origin &&
parent.location.href !== location.href) { // parent.location.href !== location.href) {
chrome.runtime.connect({name: 'getStyles:' + JSON.stringify(msg)}); // chrome.runtime.connect({name: 'getStyles:' + JSON.stringify(msg)});
return true; // return true;
} // }
} catch (e) {} // } catch (e) {}
} // }
} // }
function applyOnMessage(request) { function applyOnMessage(request) {
if (!chrome.app && document instanceof XMLDocument && request.method !== 'ping') { if (!chrome.app && document instanceof XMLDocument && request.method !== 'ping') {
@ -320,34 +320,6 @@
return el; return el;
} }
function setContentsInPageContext() {
try {
(document.head || ROOT).appendChild(document.createElement('script')).text = `(${queue => {
document.currentScript.remove();
for (const {id, code} of queue) {
const el = document.getElementById(id) ||
document.querySelector('style.stylus[id="' + id + '"]');
if (!el) continue;
const {disabled} = el.sheet;
el.textContent = code;
el.sheet.disabled = disabled;
}
}})(${JSON.stringify(pageContextQueue)})`;
} catch (e) {}
let failedSome;
for (const {el, code} of pageContextQueue) {
if (el.textContent !== code) {
el.textContent = code;
failedSome = true;
}
}
if (failedSome) {
console.debug('Could not set code of some styles in page context, ' +
'see https://github.com/openstyles/stylus/issues/461');
}
pageContextQueue.length = 0;
}
function addStyleElement(newElement) { function addStyleElement(newElement) {
if (!ROOT) { if (!ROOT) {
return; return;
@ -412,14 +384,6 @@
return parseInt(el.id.substr(ID_PREFIX.length)); return parseInt(el.id.substr(ID_PREFIX.length));
} }
function countStylesInHash(styleHash) {
let num = 0;
for (const k in styleHash) {
num += !isNaN(parseInt(k)) ? 1 : 0;
}
return num;
}
function orphanCheck() { function orphanCheck() {
if (chrome.i18n && chrome.i18n.getUILanguage()) { if (chrome.i18n && chrome.i18n.getUILanguage()) {
return true; return true;

View File

@ -1,3 +1,4 @@
/* global API */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,3 +1,4 @@
/* global API */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,4 +1,4 @@
/* global cloneInto msg */ /* global cloneInto msg API */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,4 +1,6 @@
/* global regExpTester debounce messageBox CodeMirror template colorMimicry msg */ /* global regExpTester debounce messageBox CodeMirror template colorMimicry msg
$ $create t prefs tryCatch */
/* exported createAppliesToLineWidget */
'use strict'; 'use strict';
function createAppliesToLineWidget(cm) { function createAppliesToLineWidget(cm) {

View File

@ -1,7 +1,5 @@
/* /* global loadScript css_beautify showHelp prefs t $ $create */
global CodeMirror loadScript css_beautify /* exported beautify */
global getSectionForChild showHelp
*/
'use strict'; 'use strict';
function beautify(scope) { function beautify(scope) {

View File

@ -1,4 +1,4 @@
/* global CodeMirror prefs loadScript editor */ /* global CodeMirror prefs loadScript editor $ template */
'use strict'; 'use strict';

View File

@ -1,4 +1,5 @@
/* global CodeMirror loadScript rerouteHotkeys */ /* global CodeMirror loadScript rerouteHotkeys prefs $ debounce $create */
/* exported cmFactory */
'use strict'; 'use strict';
/* /*
All cm instances created by this module are collected so we can broadcast prefs All cm instances created by this module are collected so we can broadcast prefs

View File

@ -1,4 +1,4 @@
/* global CodeMirror loadScript showHelp cmFactory */ /* global CodeMirror showHelp cmFactory onDOMready $ $create prefs t */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,16 +1,13 @@
/* /* global CodeMirror onDOMready prefs setupLivePrefs $ $$ $create t tHTML
global CodeMirror loadScript createSourceEditor queryTabs sessionStorageHash getOwnTab FIREFOX API tryCatch
global createSourceEditor closeCurrentTab messageBox debounce
global closeCurrentTab regExpTester messageBox beautify
global setupCodeMirror moveFocus msg createSectionsEditor rerouteHotkeys
global beautify
global sectionsToMozFormat
global moveFocus editorWorker msg createSectionsEditor rerouteHotkeys
*/ */
/* exported showCodeMirrorPopup */
'use strict'; 'use strict';
let saveSizeOnClose; let saveSizeOnClose;
let ownTabId;
// direct & reverse mapping of @-moz-document keywords and internal property names // direct & reverse mapping of @-moz-document keywords and internal property names
const propertyToCss = {urls: 'url', urlPrefixes: 'url-prefix', domains: 'domain', regexps: 'regexp'}; const propertyToCss = {urls: 'url', urlPrefixes: 'url-prefix', domains: 'domain', regexps: 'regexp'};
@ -242,29 +239,6 @@ prefs.subscribe(['editor.smartIndent'], (key, value) =>
CodeMirror.setOption('smartIndent', value)); CodeMirror.setOption('smartIndent', value));
function preinit() { function preinit() {
// make querySelectorAll enumeration code readable
// FIXME: don't extend native
['forEach', 'some', 'indexOf', 'map'].forEach(method => {
NodeList.prototype[method] = Array.prototype[method];
});
// eslint-disable-next-line no-extend-native
Object.defineProperties(Array.prototype, {
last: {
get() {
return this[this.length - 1];
},
},
rotate: {
value: function (amount) {
// negative amount == rotate left
const r = this.slice(-amount, this.length);
Array.prototype.push.apply(r, this.slice(0, this.length - r.length));
return r;
},
},
});
// preload the theme so that CodeMirror can calculate its metrics in DOMContentLoaded->setupLivePrefs() // preload the theme so that CodeMirror can calculate its metrics in DOMContentLoaded->setupLivePrefs()
new MutationObserver((mutations, observer) => { new MutationObserver((mutations, observer) => {
const themeElement = $('#cm-theme'); const themeElement = $('#cm-theme');
@ -302,7 +276,7 @@ function preinit() {
} }
getOwnTab().then(tab => { getOwnTab().then(tab => {
ownTabId = tab.id; const ownTabId = tab.id;
// use browser history back when 'back to manage' is clicked // use browser history back when 'back to manage' is clicked
if (sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href) { if (sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href) {
@ -446,21 +420,6 @@ function initStyleData() {
} }
} }
function showSectionHelp(event) {
event.preventDefault();
showHelp(t('styleSectionsTitle'), t('sectionHelp'));
}
function showAppliesToHelp(event) {
event.preventDefault();
showHelp(t('appliesLabel'), t('appliesHelp'));
}
function showToMozillaHelp(event) {
event.preventDefault();
showHelp(t('styleMozillaFormatHeading'), t('styleToMozillaFormatHelp'));
}
function showHelp(title = '', body) { function showHelp(title = '', body) {
const div = $('#help-popup'); const div = $('#help-popup');
div.className = ''; div.className = '';
@ -559,20 +518,6 @@ function showCodeMirrorPopup(title, html, options) {
return popup; return popup;
} }
function setGlobalProgress(done, total) {
const progressElement = $('#global-progress') ||
total && document.body.appendChild($create('#global-progress'));
if (total) {
const progress = (done / Math.max(done, total) * 100).toFixed(1);
progressElement.style.borderLeftWidth = progress + 'vw';
setTimeout(() => {
progressElement.title = progress + '%';
});
} else {
$.remove(progressElement);
}
}
function hideLintHeaderOnScroll() { function hideLintHeaderOnScroll() {
// workaround part2 for the <details> not showing its toggle icon: hide <summary> on scroll // workaround part2 for the <details> not showing its toggle icon: hide <summary> on scroll
const newOpacity = this.scrollTop === 0 ? '' : '0'; const newOpacity = this.scrollTop === 0 ? '' : '0';
@ -610,14 +555,3 @@ function isWindowMaximized() {
window.outerHeight < screen.availHeight + 10 window.outerHeight < screen.availHeight + 10
); );
} }
function toggleContextMenuDelete(event) {
if (chrome.contextMenus && event.button === 2 && prefs.get('editor.contextDelete')) {
chrome.contextMenus.update('editor.contextDelete', {
enabled: Boolean(
this.selectionStart !== this.selectionEnd ||
this.somethingSelected && this.somethingSelected()
),
}, ignoreChromeError);
}
}

View File

@ -1,3 +1,4 @@
/* exported editorWorker */
'use strict'; 'use strict';
// eslint-disable-next-line no-var // eslint-disable-next-line no-var

View File

@ -1,8 +1,4 @@
/* /* global showHelp $ $$ debounce API template t */
global messageBox resolveWith
gloabl editor showHelp getSectionsHashes
global popupExclusions
*/
'use strict'; 'use strict';
const exclusions = (() => { const exclusions = (() => {
@ -142,9 +138,9 @@ const exclusions = (() => {
if (msg.method === 'exclusionsUpdated' && msg.style && msg.style.exclusions) { if (msg.method === 'exclusionsUpdated' && msg.style && msg.style.exclusions) {
update({list: Object.keys(msg.style.exclusions), isUpdating: true}); update({list: Object.keys(msg.style.exclusions), isUpdating: true});
// update popup, if loaded // update popup, if loaded
if (typeof popupExclusions !== 'undefined') { // if (typeof popupExclusions !== 'undefined') {
popupExclusions.selectExclusions(msg.style.exclusions); // popupExclusions.selectExclusions(msg.style.exclusions);
} // }
} }
} }
@ -162,7 +158,6 @@ const exclusions = (() => {
style.exclusions = exclusionList; style.exclusions = exclusionList;
style.reason = 'exclusionsUpdated'; style.reason = 'exclusionsUpdated';
API.saveStyle(style); API.saveStyle(style);
notifyAllTabs({method: 'exclusionsUpdated', style, id, excluded: exclusionList});
}); });
} }

View File

@ -1,6 +1,5 @@
/* global CodeMirror */ /* global CodeMirror focusAccessibility colorMimicry editor
/* global focusAccessibility */ onDOMready $ $$ $create t debounce tryRegExp stringAsRegExp template */
/* global colorMimicry editor */
'use strict'; 'use strict';
onDOMready().then(() => { onDOMready().then(() => {

View File

@ -1,5 +1,6 @@
/* global memoize editorWorker showCodeMirrorPopup loadScript messageBox /* global memoize editorWorker showCodeMirrorPopup loadScript messageBox
LINTER_DEFAULTS rerouteHotkeys */ LINTER_DEFAULTS rerouteHotkeys $ $create $createLink tryJSONparse t
chromeSync */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,7 +1,7 @@
/* exported LINTER_DEFAULTS */
'use strict'; 'use strict';
// eslint-disable-next-line no-var const LINTER_DEFAULTS = (() => {
var LINTER_DEFAULTS = (() => {
const SEVERITY = {severity: 'warning'}; const SEVERITY = {severity: 'warning'};
const STYLELINT = { const STYLELINT = {
// 'sugarss' is a indent-based syntax like Sass or Stylus // 'sugarss' is a indent-based syntax like Sass or Stylus

View File

@ -1,4 +1,4 @@
/* global LINTER_DEFAULTS linter editorWorker */ /* global LINTER_DEFAULTS linter editorWorker prefs chromeSync */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,4 +1,5 @@
/* global showHelp editorWorker memoize */ /* global showHelp editorWorker memoize $ $create $createLink t */
/* exported createLinterHelpDialog */
'use strict'; 'use strict';
function createLinterHelpDialog(getIssues) { function createLinterHelpDialog(getIssues) {

View File

@ -1,4 +1,5 @@
/* global linter */ /* global linter API */
/* exported createMetaCompiler */
'use strict'; 'use strict';
function createMetaCompiler(cm) { function createMetaCompiler(cm) {

View File

@ -1,7 +1,6 @@
/* global linter editor clipString createLinterHelpDialog makeSectionVisible */ /* global linter editor clipString createLinterHelpDialog $ $create */
'use strict'; 'use strict';
// eslint-disable-next-line no-var
Object.assign(linter, (() => { Object.assign(linter, (() => {
const tables = new Map(); const tables = new Map();
const helpDialog = createLinterHelpDialog(getIssues); const helpDialog = createLinterHelpDialog(getIssues);

View File

@ -1,7 +1,8 @@
/* global prefs */
'use strict'; 'use strict';
// eslint-disable-next-line no-var /* exported linter */
var linter = (() => { const linter = (() => {
const lintingUpdatedListeners = []; const lintingUpdatedListeners = [];
const unhookListeners = []; const unhookListeners = [];
const linters = []; const linters = [];

View File

@ -1,4 +1,5 @@
/* global messageBox editor */ /* global messageBox editor $ prefs */
/* exported createLivePreview */
'use strict'; 'use strict';
function createLivePreview(preprocess) { function createLivePreview(preprocess) {

View File

@ -1,4 +1,4 @@
/* global CodeMirror */ /* global CodeMirror prefs */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,8 +1,8 @@
/* global showHelp */ /* global showHelp $ $create tryRegExp queryTabs URLS t template openURL */
/* exported regExpTester */
'use strict'; 'use strict';
// eslint-disable-next-line no-var const regExpTester = (() => {
var regExpTester = (() => {
const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain='; const GET_FAVICON_URL = 'https://www.google.com/s2/favicons?domain=';
const OWN_ICON = chrome.runtime.getManifest().icons['16']; const OWN_ICON = chrome.runtime.getManifest().icons['16'];
const cachedRegexps = new Map(); const cachedRegexps = new Map();

View File

@ -1,4 +1,5 @@
/* global CodeMirror editor */ /* global CodeMirror editor debounce */
/* exported rerouteHotkeys */
'use strict'; 'use strict';
const rerouteHotkeys = (() => { const rerouteHotkeys = (() => {

View File

@ -1,10 +1,11 @@
/* global dirtyReporter showToMozillaHelp /* global dirtyReporter showHelp prefs ignoreChromeError
showSectionHelp toggleContextMenuDelete setGlobalProgress maximizeCodeHeight CodeMirror propertyToCss
CodeMirror nextPrevEditorOnKeydown showAppliesToHelp propertyToCss
regExpTester linter createLivePreview showCodeMirrorPopup regExpTester linter createLivePreview showCodeMirrorPopup
sectionsToMozFormat editorWorker messageBox clipString beautify sectionsToMozFormat editorWorker messageBox clipString beautify
rerouteHotkeys cmFactory CssToProperty rerouteHotkeys cmFactory CssToProperty template $ $$ $create t FIREFOX API
debounce tryRegExp
*/ */
/* exported createSectionsEditor */
'use strict'; 'use strict';
function createResizeGrip(cm) { function createResizeGrip(cm) {
@ -98,6 +99,7 @@ function createSectionsEditor(style) {
$('#to-mozilla-help').addEventListener('click', showToMozillaHelp); $('#to-mozilla-help').addEventListener('click', showToMozillaHelp);
$('#from-mozilla').addEventListener('click', () => fromMozillaFormat()); $('#from-mozilla').addEventListener('click', () => fromMozillaFormat());
$('#save-button').addEventListener('click', saveStyle); $('#save-button').addEventListener('click', saveStyle);
// FIXME: this element doesn't exist?
$('#sections-help').addEventListener('click', showSectionHelp); $('#sections-help').addEventListener('click', showSectionHelp);
document.addEventListener('wheel', scrollEntirePageOnCtrlShift); document.addEventListener('wheel', scrollEntirePageOnCtrlShift);
@ -148,6 +150,46 @@ function createSectionsEditor(style) {
getSearchableInputs, getSearchableInputs,
}; };
function toggleContextMenuDelete(event) {
if (chrome.contextMenus && event.button === 2 && prefs.get('editor.contextDelete')) {
chrome.contextMenus.update('editor.contextDelete', {
enabled: Boolean(
this.selectionStart !== this.selectionEnd ||
this.somethingSelected && this.somethingSelected()
),
}, ignoreChromeError);
}
}
function setGlobalProgress(done, total) {
const progressElement = $('#global-progress') ||
total && document.body.appendChild($create('#global-progress'));
if (total) {
const progress = (done / Math.max(done, total) * 100).toFixed(1);
progressElement.style.borderLeftWidth = progress + 'vw';
setTimeout(() => {
progressElement.title = progress + '%';
});
} else {
$.remove(progressElement);
}
}
function showToMozillaHelp(event) {
event.preventDefault();
showHelp(t('styleMozillaFormatHeading'), t('styleToMozillaFormatHelp'));
}
function showAppliesToHelp(event) {
event.preventDefault();
showHelp(t('appliesLabel'), t('appliesHelp'));
}
function showSectionHelp(event) {
event.preventDefault();
showHelp(t('styleSectionsTitle'), t('sectionHelp'));
}
function getSearchableInputs(cm) { function getSearchableInputs(cm) {
return sections.find(s => s.cm === cm).appliesTo.map(a => a.valueEl).filter(Boolean); return sections.find(s => s.cm === cm).appliesTo.map(a => a.valueEl).filter(Boolean);
} }

View File

@ -1,4 +1,5 @@
/* global CodeMirror showHelp */ /* global CodeMirror showHelp onDOMready $ $$ $create template t
prefs stringAsRegExp */
'use strict'; 'use strict';
onDOMready().then(() => { onDOMready().then(() => {

View File

@ -1,9 +1,9 @@
/* /* global dirtyReporter
global CodeMirror dirtyReporter createAppliesToLineWidget messageBox
global createAppliesToLineWidget messageBox sectionsToMozFormat
global sectionsToMozFormat createMetaCompiler linter createLivePreview cmFactory $ $create API prefs t
global createMetaCompiler linter createLivePreview cmFactory chromeSync */
*/ /* exported createSourceEditor */
'use strict'; 'use strict';
function createSourceEditor(style) { function createSourceEditor(style) {

View File

@ -1,3 +1,4 @@
/* exported dirtyReporter memoize clipString sectionsToMozFormat */
'use strict'; 'use strict';
function dirtyReporter() { function dirtyReporter() {

View File

@ -1,5 +1,5 @@
/* global CodeMirror semverCompare closeCurrentTab */ /* global CodeMirror semverCompare closeCurrentTab messageBox download
/* global messageBox download chromeLocal */ $ $$ $create $createLink t prefs API getTab */
'use strict'; 'use strict';
(() => { (() => {

View File

@ -1,5 +1,7 @@
/* exported createCache */
'use strict'; 'use strict';
// create a FIFO limit-size map.
function createCache(size = 1000) { function createCache(size = 1000) {
const map = new Map(); const map = new Map();
const buffer = Array(size); const buffer = Array(size);

View File

@ -1,9 +1,35 @@
/* global prefs */
/* exported scrollElementIntoView animateElement enforceInputRange $createLink
setupLivePrefs moveFocus */
'use strict'; 'use strict';
if (!/^Win\d+/.test(navigator.platform)) { if (!/^Win\d+/.test(navigator.platform)) {
document.documentElement.classList.add('non-windows'); document.documentElement.classList.add('non-windows');
} }
// make querySelectorAll enumeration code readable
// FIXME: avoid extending native?
['forEach', 'some', 'indexOf', 'map'].forEach(method => {
NodeList.prototype[method] = Array.prototype[method];
});
// eslint-disable-next-line no-extend-native
Object.defineProperties(Array.prototype, {
last: {
get() {
return this[this.length - 1];
},
},
rotate: {
value: function (amount) {
// negative amount == rotate left
const r = this.slice(-amount, this.length);
Array.prototype.push.apply(r, this.slice(0, this.length - r.length));
return r;
},
},
});
// polyfill for old browsers to enable [...results] and for-of // polyfill for old browsers to enable [...results] and for-of
for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection]) { for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection]) {
if (!type.prototype[Symbol.iterator]) { if (!type.prototype[Symbol.iterator]) {

View File

@ -1,3 +1,5 @@
/* global tryCatch */
/* exported tHTML formatDate */
'use strict'; 'use strict';
const template = {}; const template = {};

View File

@ -1,14 +1,13 @@
/* /* exported getActiveTab onTabReady stringAsRegExp getTabRealURL openURL
global BG: true getStyleWithNoCode tryRegExp sessionStorageHash download
global FIREFOX: true closeCurrentTab */
global onRuntimeMessage applyOnMessage
*/
'use strict'; 'use strict';
const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]); const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]);
const OPERA = Boolean(chrome.app) && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]); const OPERA = Boolean(chrome.app) && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]);
const VIVALDI = Boolean(chrome.app) && navigator.userAgent.includes('Vivaldi'); const VIVALDI = Boolean(chrome.app) && navigator.userAgent.includes('Vivaldi');
const ANDROID = !chrome.windows; // FIXME: who use this?
// const ANDROID = !chrome.windows;
let FIREFOX = !chrome.app && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]); let FIREFOX = !chrome.app && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]);
if (!CHROME && !chrome.browserAction.openPopup) { if (!CHROME && !chrome.browserAction.openPopup) {
@ -120,13 +119,6 @@ function getActiveTab() {
.then(tabs => tabs[0]); .then(tabs => tabs[0]);
} }
function getActiveTabRealURL() {
return getActiveTab()
.then(getTabRealURL);
}
function getTabRealURL(tab) { function getTabRealURL(tab) {
return new Promise(resolve => { return new Promise(resolve => {
if (tab.url !== 'chrome://newtab/' || URLS.chromeProtectsNTP) { if (tab.url !== 'chrome://newtab/' || URLS.chromeProtectsNTP) {
@ -487,27 +479,6 @@ function download(url, {
} }
} }
function invokeOrPostpone(isInvoke, fn, ...args) {
return isInvoke
? fn(...args)
: setTimeout(invokeOrPostpone, 0, true, fn, ...args);
}
function openEditor({id}) {
let url = '/edit.html';
if (id) {
url += `?id=${id}`;
}
if (chrome.windows && prefs.get('openEditInWindow')) {
chrome.windows.create(Object.assign({url}, prefs.get('windowPosition')));
} else {
openURL({url});
}
}
function closeCurrentTab() { function closeCurrentTab() {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1409375 // https://bugzilla.mozilla.org/show_bug.cgi?id=1409375
getOwnTab().then(tab => { getOwnTab().then(tab => {
@ -516,6 +487,3 @@ function closeCurrentTab() {
} }
}); });
} }
// FIXME: remove this when #510 is merged
function notifyAllTabs() {}

View File

@ -1,4 +1,5 @@
/* global parserlib */ /* global parserlib */
/* exported parseMozFormat */
'use strict'; 'use strict';
/** /**

View File

@ -1,4 +1,5 @@
/* global promisify deepCopy */ /* global promisify deepCopy */
/* exported msg API */
// deepCopy is only used if the script is executed in extension pages. // deepCopy is only used if the script is executed in extension pages.
'use strict'; 'use strict';

View File

@ -1,4 +1,3 @@
/* global deepCopy debounce API tryJSONparse chromeSync FIREFOX CHROME */
/* exported prefs */ /* exported prefs */
'use strict'; 'use strict';

View File

@ -1,4 +1,4 @@
/* global loadScript tryJSONparse API */ /* global loadScript tryJSONparse */
/* exported chromeLocal chromeSync */ /* exported chromeLocal chromeSync */
'use strict'; 'use strict';