Skip to content

Commit afa19da

Browse files
authored
Merge pull request #1 from codeeshop-oc/anant
updated dist folder
2 parents 0ed4a13 + 5966bc0 commit afa19da

36 files changed

+67129
-2
lines changed
926 KB
Binary file not shown.
926 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Global CSS used within your BEX. This is not preprocessed so this has to be pure CSS. */
2+
.target-some-header-class {
3+
margin-top: 62px;
4+
}
3.43 KB
Loading
528 Bytes
Loading
1.22 KB
Loading
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Hooks added here have a bridge allowing communication between the BEX Background Script and the BEX Content Script.
2+
// Note: Events sent from this background script using `bridge.send` can be `listen`'d for by all client BEX bridges for this BEX
3+
4+
// More info: https://quasar.dev/quasar-cli/developing-browser-extensions/background-hooks
5+
6+
export default function attachBackgroundHooks(bridge /* , allActiveConnections */ ) {
7+
8+
bridge.on('storage.get', event => {
9+
const payload = event.data
10+
if (payload.key === null) {
11+
chrome.storage.local.get(null, r => {
12+
const result = []
13+
14+
// Group the items up into an array to take advantage of the bridge's chunk splitting.
15+
for (const itemKey in r) {
16+
result.push(r[itemKey])
17+
}
18+
bridge.send(event.eventResponseKey, result)
19+
})
20+
} else {
21+
chrome.storage.local.get([payload.key], r => {
22+
bridge.send(event.eventResponseKey, r[payload.key])
23+
})
24+
}
25+
})
26+
27+
bridge.on('storage.set', event => {
28+
const payload = event.data
29+
chrome.storage.local.set({
30+
[payload.key]: payload.data
31+
}, () => {
32+
bridge.send(event.eventResponseKey, payload.data)
33+
})
34+
})
35+
36+
bridge.on('storage.remove', event => {
37+
const payload = event.data
38+
chrome.storage.local.remove(payload.key, () => {
39+
bridge.send(event.eventResponseKey, payload.data)
40+
})
41+
})
42+
43+
/*
44+
// EXAMPLES
45+
// Listen to a message from the client
46+
bridge.on('test', d => {
47+
console.log(d)
48+
})
49+
50+
// Send a message to the client based on something happening.
51+
chrome.tabs.onCreated.addListener(tab => {
52+
bridge.send('browserTabCreated', { tab })
53+
})
54+
55+
// Send a message to the client based on something happening.
56+
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
57+
if (changeInfo.url) {
58+
bridge.send('browserTabUpdated', { tab, changeInfo })
59+
}
60+
})
61+
*/
62+
63+
chrome.tabs.query({
64+
active: true
65+
}, function(tabs) {
66+
try {
67+
var activeTab = tabs[0];
68+
init(activeTab.url)
69+
} catch (err) {
70+
console.warn(err)
71+
}
72+
});
73+
74+
function init(current_active_url) {
75+
76+
const QuasarStorageToString = (val) => {
77+
return val.substring(9)
78+
}
79+
80+
const StringToJSON = val => {
81+
return JSON.parse(val)
82+
}
83+
84+
const getStorageValue = key => {
85+
return StringToJSON(QuasarStorageToString(localStorage.getItem(key)))
86+
}
87+
88+
const isExcluded = (current_url, excluded_urls) => {
89+
let new_excluded_urls = excluded_urls.split(',')
90+
let isExcludedBool = false
91+
for (var i = new_excluded_urls.length - 1; i >= 0; i--) {
92+
if (new_excluded_urls[i] == current_url) {
93+
isExcludedBool = true
94+
break;
95+
}
96+
}
97+
98+
return isExcludedBool
99+
}
100+
101+
const getOriginFromURL = url => {
102+
let resp = ''
103+
try {
104+
if(!['', 'all'].includes(url)) {
105+
const myUrl = new URL(url)
106+
resp = myUrl['origin']
107+
}
108+
} catch(err) {
109+
console.warn(err)
110+
}
111+
return resp
112+
}
113+
114+
const checkURLScriptToAdd = (url) => {
115+
let curr_origin = getOriginFromURL(url)
116+
117+
let found = false
118+
let data = false
119+
for (var i = 0; i < localStorage.length; i++) {
120+
data = getStorageValue(localStorage.key(i))
121+
// data.included_url
122+
let new_origin = getOriginFromURL(data.included_url)
123+
124+
if (data.included_url != 'all' && (data.included_url == url || new_origin == curr_origin)) {
125+
found = true
126+
break;
127+
}
128+
}
129+
130+
if (!found) {
131+
data = false
132+
if (localStorage.getItem('all') != null) {
133+
data = getStorageValue('all')
134+
}
135+
}
136+
137+
if (data && !isExcluded(url, data.excluded_url)) {
138+
bridge.send('browserURLChanged', {
139+
...data,
140+
...{
141+
current_active_url: current_active_url
142+
}
143+
});
144+
}
145+
// switch()
146+
}
147+
148+
checkURLScriptToAdd(current_active_url)
149+
}
150+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Background code goes here
2+
chrome.browserAction.onClicked.addListener((/* tab */) => {
3+
// Opens our extension in a new browser window.
4+
// Only if a popup isn't defined in the manifest.
5+
chrome.tabs.create({
6+
url: chrome.extension.getURL('www/index.html')
7+
}, (/* newTab */) => {
8+
// Tab opened.
9+
})
10+
})
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const
2+
iFrame = document.createElement('iframe'),
3+
defaultFrameHeight = '0'
4+
5+
/**
6+
* Set the height of our iFrame housing our BEX
7+
* @param height
8+
*/
9+
const setIFrameHeight = height => {
10+
iFrame.height = height
11+
}
12+
13+
/**
14+
* Reset the iFrame to its default height e.g The height of the top bar.
15+
*/
16+
const resetIFrameHeight = () => {
17+
setIFrameHeight(defaultFrameHeight)
18+
}
19+
20+
/**
21+
* Content hooks which listen for messages from the BEX in the iFrame
22+
* @param bridge
23+
*/
24+
export default function attachContentHooks(bridge) {
25+
/**
26+
* When the drawer is toggled set the iFrame height to take the whole page.
27+
* Reset when the drawer is closed.
28+
*/
29+
// bridge.on('wb.drawer.toggle', event => {
30+
// const payload = event.data
31+
// if (payload.open) {
32+
// setIFrameHeight('100%')
33+
// } else {
34+
// resetIFrameHeight()
35+
// }
36+
// bridge.send(event.eventResponseKey)
37+
// })
38+
39+
bridge.on('browserURLChanged', event => {
40+
const payload = event.data
41+
42+
if (payload.current_active_url == window.location.href || payload.current_active_url == window.location.origin) {
43+
bridge.send(event.eventResponseKey)
44+
// remove the previous code
45+
if(document.querySelector('.custom_html_in_pages')) document.querySelector('.custom_html_in_pages').parentNode.removeChild(document.querySelector('.custom_html_in_pages'))
46+
const fragment = document.createRange().createContextualFragment(payload.content);
47+
document.head.prepend(fragment);
48+
// document.head.insertAdjacentHTML('afterbegin', payload.content);
49+
50+
// if(!process.env.PROD) {
51+
// var script = document.createElement('script');
52+
// script.type = 'text/javascript';
53+
// script.src = 'https://www.bugherd.com/sidebarv2.js?apikey=gbisld9y95s7vajcukdjqg';
54+
// document.head.appendChild(script);
55+
// }
56+
57+
}
58+
})
59+
}
60+
61+
/**
62+
* The code below will get everything going. Initialize the iFrame with defaults and add it to the page.
63+
* @type {string}
64+
*/
65+
iFrame.id = 'custom-html-in-pages-iframe'
66+
iFrame.width = '100%'
67+
resetIFrameHeight()
68+
69+
// Assign some styling so it looks seamless
70+
Object.assign(iFrame.style, {
71+
position: 'fixed',
72+
top: '0',
73+
right: '0',
74+
bottom: '0',
75+
left: '0',
76+
border: '0',
77+
zIndex: '9999999', // Make sure it's on top
78+
overflow: 'visible'
79+
})
80+
81+
;
82+
(function() {
83+
// When the page loads, insert our browser extension app.
84+
iFrame.src = chrome.runtime.getURL(`www/index.html`)
85+
document.body.prepend(iFrame)
86+
})()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Content script content goes here or in activatedContentHooks (use activatedContentHooks if you need a variable
2+
// accessible to both the content script and inside a hook

0 commit comments

Comments
 (0)