put https://top.site.origin in "stylus-iframe" attr

This commit is contained in:
tophf 2018-01-19 15:37:26 +03:00
parent 75aee2085a
commit a3962b7adf
3 changed files with 30 additions and 6 deletions

View File

@ -1212,7 +1212,7 @@
"message": "Expose iframes via HTML[stylus-iframe]" "message": "Expose iframes via HTML[stylus-iframe]"
}, },
"optionsAdvancedExposeIframesNote": { "optionsAdvancedExposeIframesNote": {
"message": "Enables writing iframe-specific CSS like 'html[stylus-iframe] h1 { display:none }'" "message": "Exposes the top site domain in each iframe.\nEnables writing iframe-specific CSS like this:\nhtml[stylus-iframe$=\"twitter.com\"] h1 { display:none }"
}, },
"optionsAdvancedContextDelete": { "optionsAdvancedContextDelete": {
"message": "Add 'Delete' in editor context menu" "message": "Add 'Delete' in editor context menu"

View File

@ -247,14 +247,38 @@ window.addEventListener('storageReady', function _() {
})); }));
}); });
// *************************************************************************
{
const getStylesForFrame = (msg, sender) => {
const stylesTask = getStyles(msg);
if (!sender || !sender.frameId) return stylesTask;
return Promise.all([
stylesTask,
getTab(sender.tab.id),
]).then(([styles, tab]) => {
if (tab) styles.exposeIframes = tab.url.replace(/(\/\/[^/]*).*/, '$1');
return styles;
});
};
const updateAPI = (_, enabled) => {
window.API_METHODS.getStylesForFrame = enabled ? getStylesForFrame : getStyles;
};
prefs.subscribe(['exposeIframes'], updateAPI);
updateAPI(null, prefs.readOnlyValues.exposeIframes);
}
// ************************************************************************* // *************************************************************************
function webNavigationListener(method, {url, tabId, frameId}) { function webNavigationListener(method, {url, tabId, frameId}) {
getStyles({matchUrl: url, asHash: true}).then(styles => { Promise.all([
getStyles({matchUrl: url, asHash: true}),
frameId && prefs.readOnlyValues.exposeIframes && getTab(tabId),
]).then(([styles, tab]) => {
if (method && URLS.supported(url) && tabId >= 0) { if (method && URLS.supported(url) && tabId >= 0) {
if (method === 'styleApply') { if (method === 'styleApply') {
handleCssTransitionBug({tabId, frameId, url, styles}); handleCssTransitionBug({tabId, frameId, url, styles});
} }
if (tab) styles.exposeIframes = tab.url.replace(/(\/\/[^/]*).*/, '$1');
sendMessage({ sendMessage({
tabId, tabId,
frameId, frameId,

View File

@ -43,7 +43,7 @@
} catch (e) {} } catch (e) {}
} }
const request = Object.assign({ const request = Object.assign({
method: 'getStyles', method: 'getStylesForFrame',
asHash: true, asHash: true,
matchUrl, matchUrl,
}, options); }, options);
@ -143,9 +143,9 @@
} }
exposeIframes = state; exposeIframes = state;
const attr = document.documentElement.getAttribute('stylus-iframe'); const attr = document.documentElement.getAttribute('stylus-iframe');
if (state && attr !== '') { if (state && state !== attr) {
document.documentElement.setAttribute('stylus-iframe', ''); document.documentElement.setAttribute('stylus-iframe', state);
} else if (!state && attr === '') { } else if (!state && attr !== undefined) {
document.documentElement.removeAttribute('stylus-iframe'); document.documentElement.removeAttribute('stylus-iframe');
} }
} }