Skip to content

Commit 550bf18

Browse files
committed
Add build files & gitignore
1 parent 8b8186d commit 550bf18

17 files changed

+475
-267
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Project Name : Visual Python
3+
# Description : GUI-based Python code generator
4+
# File Name : build.sh
5+
# Author : Black Logic - Minju
6+
# Note : Build Visual Python for All
7+
# License : GPLv3 (GNU General Public License v3.0)
8+
# Date : 2023. 02. 08
9+
# Change Date :
10+
#

colab/background.js

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,74 @@
1-
//======================================================================
2-
// Event for extension icon - toggle
3-
//======================================================================
4-
chrome.action.onClicked.addListener((tab) => {
5-
// check origin if its url is matching our rule
6-
let checkOrigin = tab.url.startsWith('https://colab.research.google.com/');
7-
if (checkOrigin) {
8-
console.log('send toggle', checkOrigin, tab.id, tab);
9-
// send toggle action to content
10-
chrome.tabs.sendMessage(tab.id, "toggle").then(function(result) {
11-
// success
12-
console.log('ok', result);
13-
}).catch(function(result) {
14-
// error: if no content script, execute script again
15-
console.log('error', result);
16-
// execute script manually
17-
chrome.scripting.executeScript({
18-
target: { tabId: tab.id },
19-
files: ['content.js']
20-
}).then(function(result) {
21-
// toggle again
22-
chrome.tabs.sendMessage(tab.id, "toggle");
23-
});
24-
});
25-
} else {
26-
console.log("it's not colab site...");
27-
}
28-
});
29-
1+
//======================================================================
2+
// Event for extension icon - toggle
3+
//======================================================================
4+
chrome.action.onClicked.addListener((tab) => {
5+
// check origin if its url is matching our rule
6+
let checkOrigin = tab.url.startsWith('https://colab.research.google.com/');
7+
if (checkOrigin) {
8+
console.log('send toggle', checkOrigin, tab.id, tab);
9+
// send toggle action to content
10+
chrome.tabs.sendMessage(tab.id, { type: 'toggle' }).then(function(result) {
11+
// success
12+
console.log('ok', result);
13+
}).catch(function(result) {
14+
// error: if no content script, execute script again
15+
console.log('error', result);
16+
// execute script manually
17+
chrome.scripting.executeScript({
18+
target: { tabId: tab.id },
19+
files: ['content.js']
20+
}).then(function(result) {
21+
// toggle again
22+
chrome.tabs.sendMessage(tab.id, { type: 'toggle' });
23+
});
24+
});
25+
} else {
26+
console.log("it's not colab site...");
27+
}
28+
});
29+
30+
//======================================================================
31+
// Event for check tab to disable or enable extension
32+
//======================================================================
33+
// check status on tab activated and check colab exist
34+
chrome.tabs.onActivated.addListener(function() {
35+
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function(tabs) {
36+
if (tabs && tabs.length > 0) {
37+
let tabUrl = tabs[0].url;
38+
let isColabExist = tabUrl.startsWith('https://colab.research.google.com/');
39+
if (isColabExist == true) {
40+
// reset
41+
// chrome.action.setBadgeText({ text: '' });
42+
chrome.action.setPopup({ popup: '' });
43+
} else {
44+
// set badge and popup
45+
// chrome.action.setBadgeBackgroundColor({ color: 'red' });
46+
// chrome.action.setBadgeText({ text: ':(' });
47+
chrome.action.setPopup({ popup: 'popup.html' });
48+
}
49+
}
50+
51+
});
52+
});
53+
// check status on tab updated
54+
chrome.tabs.onUpdated.addListener(function() {
55+
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function(tabs) {
56+
if (tabs && tabs.length > 0) {
57+
let tabUrl = tabs[0].url;
58+
let isColabExist = tabUrl.startsWith('https://colab.research.google.com/');
59+
if (isColabExist == true) {
60+
// reset
61+
// chrome.action.setBadgeText({ text: '' });
62+
chrome.action.setPopup({ popup: '' });
63+
} else {
64+
// set badge and popup
65+
// chrome.action.setBadgeBackgroundColor({ color: 'red' });
66+
// chrome.action.setBadgeText({ text: ':(' });
67+
chrome.action.setPopup({ popup: 'popup.html' });
68+
}
69+
}
70+
71+
});
72+
});
73+
3074
// End of file

colab/build.colab.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Project Name : Visual Python
3+
# Description : GUI-based Python code generator
4+
# File Name : build.colab.sh
5+
# Author : Black Logic - Minju
6+
# Note : Build Visual Python for Colab
7+
# License : GPLv3 (GNU General Public License v3.0)
8+
# Date : 2023. 02. 08
9+
# Change Date :
10+
#
11+
12+
# set visualpython version
13+
export VP_ORG_VER=2.2.12
14+
export VP_NEW_VER=2.2.13
15+
16+
# make directories to save build output
17+
mkdir -p ../dist/colab
18+
19+
# update version info
20+
# rsync -av --exclude='path1/in/source' --exclude='path2/in/source' [source]/ [destination]
21+
rm -rf ../dist/colab/visualpython-v$VP_NEW_VER/*
22+
rsync -avk --exclude='./build.colab.sh' ../colab/ ../dist/colab/visualpython-v$VP_NEW_VER/
23+
grep -REil ${VP_ORG_VER//\./\\.} setup.py visualpython/* | xargs sed -i --follow-symlinks "s/${VP_ORG_VER//\./\\.}/${VP_NEW_VER}/g"
24+
25+
# build package
26+
zip -r ../dist/colab/visualpython-v$VP_NEW_VER.zip background.js content.js icon.png inject.js manifest.json visualpython
27+
28+
exit 0
29+
# End of file

colab/content.js

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1-
//======================================================================
2-
// Inner functions
3-
//======================================================================
4-
/**
5-
* Send event to inject script
6-
* @param {*} type event type defined on inject script
7-
* @param {*} data data to send
8-
*/
9-
function sendEvent(type, data='') {
10-
let detailObj = { type: type, data: data };
11-
let evt = new CustomEvent('vpcomm', { bubbles: true, detail: detailObj });
12-
console.log('[vp content] send from content - ', type, data, evt);
13-
document.dispatchEvent(evt);
14-
15-
}
16-
function checkScriptExists(url) {
17-
return document.querySelectorAll(`script[src="${url}"]`).length > 0;
18-
}
19-
/**
20-
* Inject file
21-
*/
22-
function injectFile() {
23-
let url = chrome.runtime.getURL('inject.js');
24-
console.log('[vp content] check inject file...')
25-
if (checkScriptExists(url)) {
26-
console.log('[vp content] inject file already exist!');
27-
return false;
28-
}
29-
console.log('[vp content] inject file!');
30-
// inject script
31-
var s = document.createElement('script');
32-
s.src = url;
33-
s.onload = function() {
34-
// send event to inject.js to send its url
35-
var url = chrome.runtime.getURL('');
36-
// var evt = new CustomEvent('vpcomm', { bubbles: true, detail: { type: 'sendBase', data: url } });
37-
// document.dispatchEvent(evt);
38-
sendEvent('sendBase', url);
39-
};
40-
(document.head || document.documentElement).appendChild(s);
41-
return true;
42-
}
43-
44-
//======================================================================
45-
// Event listener - background <-> inject
46-
//======================================================================
47-
function msgHandler(msg, sender) {
48-
if (msg == "toggle"){
49-
// var evt = new CustomEvent('vpcomm', { bubbles: true, detail: { type: 'toggle' } });
50-
// document.dispatchEvent(evt);
51-
// check if injected
52-
injectFile();
53-
sendEvent('toggle');
54-
}
55-
}
56-
chrome.runtime.onMessage.removeListener(msgHandler);
57-
chrome.runtime.onMessage.addListener(msgHandler);
58-
59-
console.log('[vp content] content script executed!');
60-
1+
//======================================================================
2+
// Inner functions
3+
//======================================================================
4+
/**
5+
* Send event to inject script
6+
* @param {*} type event type defined on inject script
7+
* @param {*} data data to send
8+
*/
9+
function sendEvent(type, data='') {
10+
let detailObj = { type: type, data: data };
11+
let evt = new CustomEvent('vpcomm', { bubbles: true, detail: detailObj });
12+
console.log('[vp content] send from content - ', type, data, evt);
13+
document.dispatchEvent(evt);
14+
15+
}
16+
function checkScriptExists(url) {
17+
return document.querySelectorAll(`script[src="${url}"]`).length > 0;
18+
}
19+
/**
20+
* Inject file
21+
*/
22+
function injectFile() {
23+
let url = chrome.runtime.getURL('inject.js');
24+
console.log('[vp content] check inject file...')
25+
if (checkScriptExists(url)) {
26+
console.log('[vp content] inject file already exist!');
27+
return false;
28+
}
29+
console.log('[vp content] inject file!');
30+
// inject script
31+
var s = document.createElement('script');
32+
s.src = url;
33+
s.onload = function() {
34+
// send event to inject.js to send its url
35+
var url = chrome.runtime.getURL('');
36+
// var evt = new CustomEvent('vpcomm', { bubbles: true, detail: { type: 'sendBase', data: url } });
37+
// document.dispatchEvent(evt);
38+
sendEvent('sendBase', url);
39+
};
40+
(document.head || document.documentElement).appendChild(s);
41+
return true;
42+
}
43+
44+
//======================================================================
45+
// Event listener - background <-> (content -> inject)
46+
//======================================================================
47+
function msgHandler(msg, sender) {
48+
if (msg && msg.type) {
49+
switch(msg.type) {
50+
case "toggle":
51+
injectFile();
52+
sendEvent('toggle');
53+
break;
54+
default:
55+
break;
56+
}
57+
}
58+
}
59+
chrome.runtime.onMessage.removeListener(msgHandler);
60+
chrome.runtime.onMessage.addListener(msgHandler);
61+
62+
console.log('[vp content] content script executed!');
63+
6164
// End of file

colab/icon-disable.png

1.67 KB
Loading

colab/icon128.png

574 Bytes
Loading

0 commit comments

Comments
 (0)