/* global usercss */ 'use strict'; let pendingResource; function fetchText(url) { return new Promise((resolve, reject) => { // you can't use fetch in Chrome under 'file:' protocol const xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.addEventListener('load', () => resolve(xhr.responseText)); xhr.addEventListener('error', () => reject(xhr)); xhr.send(); }); } function install(style) { const request = Object.assign(style, { method: 'saveUsercss', reason: 'install', url: location.href, updateUrl: location.href }); return communicate(request) .then(() => { $$('.warning') .forEach(el => el.remove()); $('button.install').textContent = 'Installed'; $('button.install').disabled = true; }) .catch(err => { alert(chrome.i18n.getMessage('styleInstallFailed', String(err))); }); } function communicate(request) { return new Promise((resolve, reject) => { chrome.runtime.sendMessage(request, result => { if (result.status === 'error') { reject(result.error); } else { resolve(result); } }); }); } function getAppliesTo(style) { function *_gen() { for (const section of style.sections) { for (const type of ['urls', 'urlPrefixes', 'domains', 'regexps']) { if (section[type]) { yield *section[type]; } } } } const result = [..._gen()]; if (!result.length) { result.push('All URLs'); } return result; } function initInstallPage({style, dup}) { pendingResource.then(() => { const versionTest = dup && usercss.semverTest(style.version, dup.version); document.body.innerHTML = ''; // FIXME: i18n document.body.appendChild(tHTML(`
${err}