-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from facets-io/auth-css-fix
Preview Feature via cookie management + Auth css fix
- Loading branch information
Showing
16 changed files
with
399 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
/** | ||
* Injects @param {disableMutationObserverScript} into the current page. | ||
* IIFE that injects @param {disableMutationObserverScript} into the current page. | ||
* The value is determined by the boolean attribute `facet-extension-loaded` which is defined through `mutationObserverVariableInjection.js`. | ||
*/ | ||
window.disableMutationObserverScript = false; | ||
const scriptArr = document.querySelectorAll('script'); | ||
let found = false; | ||
scriptArr.forEach(script => { | ||
if (found) { | ||
return; | ||
|
||
(async function () { | ||
|
||
const keysObj = { | ||
FACET_EXTENSION_PREVIEW_TAB_ID: 'FACET_EXTENSION_PREVIEW_TAB_ID', | ||
FACET_EXTENSION_DISABLE_MO: 'FACET_EXTENSION_DISABLE_MO', | ||
FACET_EXTENSION_ALREADY_INTEGRATED: 'FACET_EXTENSION_ALREADY_INTEGRATED', | ||
FACET_EXTENSION_INJECTING_SCRIPT_TAG: 'FACET_EXTENSION_INJECTING_SCRIPT_TAG' | ||
}; | ||
|
||
function getFacetExtensionCookie(key) { | ||
const value = `; ${document.cookie}`; | ||
const parts = value.split(`; ${key}=`); | ||
if (parts.length === 2) { | ||
return parts.pop().split(';').shift(); | ||
} | ||
} | ||
if (script.attributes && script.attributes['is-preview']) { | ||
window.disableMutationObserverScript = false; | ||
window.IN_PREVIEW = true; | ||
window.JSURL = script.attributes['src']; | ||
found = true; | ||
|
||
const alreadyIntegrated = (getFacetExtensionCookie(keysObj["FACET_EXTENSION_ALREADY_INTEGRATED"]) === 'true'); | ||
const scriptTagVal = getFacetExtensionCookie(keysObj['FACET_EXTENSION_INJECTING_SCRIPT_TAG']); | ||
if (!alreadyIntegrated) { | ||
var node = document.getElementsByTagName('html').item(0); | ||
node.style.visibility = "hidden"; | ||
var previewNode = document.createElement('div'); | ||
previewNode.setAttribute('src', window.JSURL); | ||
node.prepend(previewNode); | ||
return; | ||
|
||
var scriptTag = document.createElement('script'); | ||
scriptTag.setAttribute('type', 'text/javascript'); | ||
scriptTag.setAttribute('src', scriptTagVal); | ||
node.prepend(scriptTag); | ||
} | ||
if (script.attributes && script.attributes['facet-extension-loaded']) { | ||
window.disableMutationObserverScript = script.getAttribute("facet-extension-loaded") === "true" ? true : false; | ||
} | ||
}) | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
|
||
/** | ||
* taken from https://gist.github.com/devjin0617/3e8d72d94c1b9e69690717a219644c7a | ||
* | ||
* injectScript - Inject internal script to available access to the `window` | ||
* Injects facet-extension-window-variable-content.js | ||
* | ||
* @param {type} file_path Local path of the internal script. | ||
* @param {type} tag The tag as string, where the script will be append (default: 'body'). | ||
* @see {@link http://stackoverflow.com/questions/20499994/access-window-variable-from-content-script} | ||
*/ | ||
async function injectScript(file_path, tag) { | ||
chrome.storage && chrome.storage.sync.get('facet-settings', function (obj) { | ||
var node = document.getElementsByTagName('html')[0]; | ||
var script = document.createElement('script'); | ||
const val = Boolean(obj && obj['facet-settings'] && obj['facet-settings']['isPluginEnabled']); | ||
script.setAttribute('type', 'text/javascript'); | ||
script.setAttribute('src', file_path); | ||
script.setAttribute('facet-extension-loaded', val); | ||
node.appendChild(script); | ||
(async function () { | ||
|
||
async function injectScript(file_path, tag) { | ||
chrome.storage && chrome.storage.sync.get('facet-settings', function (obj) { | ||
var node = document.getElementsByTagName('html')[0]; | ||
var script = document.createElement('script'); | ||
const val = Boolean(obj && obj['facet-settings'] && obj['facet-settings']['isPluginEnabled']); | ||
script.setAttribute('type', 'text/javascript'); | ||
script.setAttribute('src', file_path); | ||
script.setAttribute('facet-extension-loaded', val); | ||
node.appendChild(script); | ||
}); | ||
} | ||
|
||
const keys = { | ||
'FACET_EXTENSION_DISABLE_MO': 'FACET_EXTENSION_DISABLE_MO', | ||
'FACET_EXTENSION_PREVIEW_TAB_ID': 'FACET_EXTENSION_PREVIEW_TAB_ID', | ||
'FACET_EXTENSION_ALREADY_INTEGRATED': 'FACET_EXTENSION_ALREADY_INTEGRATED', | ||
} | ||
|
||
function getFacetExtensionCookie(key) { | ||
const value = `; ${document.cookie}`; | ||
const parts = value.split(`; ${key}=`); | ||
if (parts.length === 2) { | ||
return parts.pop().split(';').shift(); | ||
} | ||
} | ||
|
||
const previewId = getFacetExtensionCookie(keys["FACET_EXTENSION_PREVIEW_TAB_ID"]); | ||
|
||
await chrome.runtime.sendMessage({ | ||
data: 'GET_CURRENT_TAB' | ||
}, async (response) => { | ||
// response.tabId | ||
const val = response.tabId != previewId; | ||
await chrome.runtime.sendMessage({ | ||
data: 'SET_COOKIE_VALUE', | ||
config: { | ||
url: window.location.origin, | ||
name: 'FACET_EXTENSION_DISABLE_MO', | ||
value: val.toString() | ||
} | ||
}); | ||
}); | ||
} | ||
injectScript(chrome.extension.getURL('facet-extension-window-variable-content.js'), 'body'); | ||
|
||
console.log("[FACET][mutationObserverVariableInjection] INJECTING facet-extension-window-variable-content.js"); | ||
injectScript(chrome.extension.getURL('facet-extension-window-variable-content.js'), 'body'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(function () { | ||
var node = document.getElementsByTagName('html').item(0); | ||
node.style.visibility = "hidden"; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.