-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gui Yazbek
committed
Feb 6, 2018
0 parents
commit 5ca27fe
Showing
23 changed files
with
888 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
dist/ | ||
dist_chrome/ | ||
dist_firefox/ | ||
Hodlit.code-workspace | ||
|
||
# Potential workspace Files | ||
.vscode | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk |
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,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2018 https://github.com/gyazbek/Hodl | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,16 @@ | ||
{ | ||
"name": "Hodl", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"package:copy": "rm -rf ./temp && mkdir ./temp && cp -r ./src/* ./temp", | ||
"package:js": "uglifyjs-folder ./temp -e -y -x .js -o ./temp --configFile ./uglify.json", | ||
"package:css": "cleancss -o ./temp/popup/options.css ./temp/popup/options.css", | ||
"package:catcommon": "cat ./temp/common.js ./temp/content.js > ./temp/content_merged.js && mv ./temp/content_merged.js ./temp/content.js && cat ./temp/common.js ./temp/background.js > ./temp/background_merged.js && mv ./temp/background_merged.js ./temp/background.js && cat ./temp/common.js ./temp/popup/options.js > ./temp/popup/options_merged.js && mv ./temp/popup/options_merged.js ./temp/popup/options.js", | ||
"package:chrome": "rm -rf ./dist_chrome && npm run package:copy && cp ./temp/platform/manifest_chrome.json ./temp/manifest.json && rm -r ./temp/platform && npm run package:catcommon && rm ./temp/common.js && npm run package:css && npm run package:js && mv ./temp ./dist_chrome", | ||
"package:firefox": "rm -rf ./dist_firefox && npm run package:copy && cp ./temp/platform/manifest_firefox.json ./temp/manifest.json && rm -r ./temp/platform && npm run package:catcommon && rm ./temp/common.js && npm run package:css && npm run package:js && mv ./temp ./dist_firefox" | ||
}, | ||
"dependencies": { | ||
"uglifyjs-folder": "1.5.0", | ||
"clean-css-cli": "4.1.10" | ||
} | ||
} |
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,33 @@ | ||
# HODL | ||
Firefox and Chrome webextension to remind you to HODL your crypto assets. | ||
The extension searches for and replaces text elements in pages of your choice. | ||
|
||
There is an initial list of domains included, but you can remove them by changing the settings in the action popup. | ||
|
||
You can also customize the search array as well as the replacement word. | ||
|
||
|
||
# Permissions | ||
We only require permissions to access the tabs, local storage for preferences, and urls. There might be some crossover, and I will potentially remove some uneeded permissions in the future. | ||
|
||
# Dependencies | ||
uglifyjs-folder | ||
clean-css-cli | ||
|
||
### Building | ||
A very simple npm script is used to build the extension for Firefox and Chrome. The script copies the appropriate files, appends the common scripts to popup, background, and content scripts, and lastly minifies. | ||
|
||
```sh | ||
$ npm run package:chrome | ||
$ npm run package:firefox | ||
``` | ||
|
||
|
||
### Development | ||
Want to help? Please do. This was built in a rush so I expect bugs. | ||
|
||
|
||
### Todos | ||
- Add tests | ||
- Add schedule mode | ||
- Advanced domain matching (subdomain/directory matching) |
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,21 @@ | ||
loadOptions().then(function() { | ||
|
||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { | ||
|
||
// if (tab.url !== undefined && changeInfo.status === 'complete' && savedOptions.matching_urls.indexOf(cleanUrl(tab.url, false)) > -1) { | ||
|
||
if (tab.url !== undefined && changeInfo.status === 'complete' && hasUrlMatch(tab.url)) { | ||
|
||
chrome.tabs.sendMessage(tab.id, {message: "marco"}, function(response) { | ||
if (!response) { | ||
chrome.tabs.executeScript(tabId, { | ||
file: 'content.js' | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
chrome.storage.onChanged.addListener(function(changes, namespace) { | ||
loadOptions(); | ||
}); | ||
}); |
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,66 @@ | ||
/* | ||
* This file contains commonly used code in the extension | ||
*/ | ||
|
||
var savedOptions = {}; | ||
|
||
const default_options = {"options_enabled":true,"matching_urls": ["coinbase.com", | ||
"gdax.com","bittrex.com","binance.com", | ||
"kraken.com", "gemini.com", "bitstamp.net", | ||
"bitflyer.jp"], "options_replacement_word":"Hodl","options_matching_words":"sell","options_match_custom_word":false,"options_locale":"en", "options_activation_on_pageload": true, "options_activation_on_interval":true, "options_activation_interval_time": 5, "options_activation_on_change": false,"options_activation_delay":false, "options_activation_delay_time": 1}; | ||
|
||
function loadOptions(){ | ||
return new Promise(function(resolve, reject) { | ||
chrome.storage.local.get(default_options, function(result) { | ||
savedOptions = result; | ||
resolve("Options loaded"); | ||
}); | ||
}); | ||
} | ||
|
||
function cleanUrl(url, preserve_path) { | ||
var hostname = url; | ||
|
||
// working from left to right, we want to extract hostname but leave path intact | ||
// remove protocol | ||
if (url.indexOf("://") > -1) { | ||
hostname = url.split('//')[1]; | ||
} | ||
|
||
// remove subdomain if www only, leave it alone if something else | ||
if (hostname.indexOf("www.") > -1){ | ||
hostname = hostname.substr(hostname.indexOf("www") + 4); | ||
} | ||
|
||
|
||
if(!preserve_path){ | ||
if(hostname.indexOf("/") > -1){ | ||
hostname = hostname.split('/')[0]; | ||
} | ||
if(hostname.indexOf("?") > -1){ | ||
hostname = hostname.split('?')[0]; | ||
} | ||
} | ||
|
||
// remove trailing slash | ||
if(hostname.substr(-1) === '/') { | ||
hostname = hostname.substr(0, hostname.length - 1); | ||
} | ||
|
||
return hostname; | ||
} | ||
|
||
function hasPath(url){ | ||
return (url.indexOf("/") > -1 || url.indexOf("?") > -1); | ||
} | ||
|
||
function hasUrlMatch(url){ | ||
var preserved = cleanUrl(url, true), cleaned = cleanUrl(url, false); | ||
for (var x = 0; x < savedOptions.matching_urls.length; x++){ | ||
if ((hasPath(savedOptions.matching_urls[x]) ? preserved : cleaned).indexOf(savedOptions.matching_urls[x]) > -1){ | ||
return true; | ||
} | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* This file contains code that drives the text search and replacement. | ||
*/ | ||
|
||
var searchDictionary = new Map(); | ||
searchDictionary.set('en', ['sell']); | ||
searchDictionary.set('de', ['verkaufen']); | ||
searchDictionary.set('es', ['vender']); | ||
searchDictionary.set('fr', ['vendre']); | ||
searchDictionary.set('it', ['vendi']); | ||
searchDictionary.set('pt', ['vender','vende']); | ||
searchDictionary.set('jp', ['売却','販']); | ||
var regexObj, intervalRunning = false; | ||
|
||
const observer = new MutationObserver((mutations) => { | ||
mutations.forEach((mutation) => { | ||
if (mutation.addedNodes && mutation.addedNodes.length > 0) { | ||
for (let i = 0; i < mutation.addedNodes.length; i++) { | ||
nodeTextReplace(mutation.addedNodes[i]); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
var nodeTextReplace = function (node) { | ||
|
||
if (node.nodeType === Node.TEXT_NODE) { | ||
if (node.parentNode && | ||
node.parentNode.nodeName !== 'TEXTAREA') { | ||
if(node.data.indexOf(savedOptions.options_replacement_word) == -1){ | ||
node.data = node.data.replace(regexObj, savedOptions.options_replacement_word); | ||
} | ||
} | ||
} | ||
// keep digging | ||
if (node.nodeType == 1 && node.nodeName != "SCRIPT") { | ||
for (var i = 0; i < node.childNodes.length; i++) { | ||
nodeTextReplace(node.childNodes[i]); | ||
} | ||
} | ||
} | ||
|
||
var initInterval = function(){ | ||
|
||
if (intervalRunning == false) { | ||
invokeTimeout(); | ||
intervalRunning = true; | ||
} | ||
} | ||
var invokeTimeout = function(){ | ||
if(savedOptions.options_activation_on_interval){ | ||
nodeTextReplace(document.body); | ||
setTimeout(invokeTimeout, savedOptions.options_activation_interval_time * 1000); | ||
}else{ | ||
intervalRunning = false; | ||
} | ||
} | ||
|
||
|
||
var preinit = function(){ | ||
loadOptions().then(function() { | ||
if(savedOptions.options_activation_delay == true){ | ||
setTimeout(init(), savedOptions.options_activation_delay_time * 1000); | ||
}else{ | ||
init(); | ||
} | ||
}); | ||
} | ||
|
||
var init = function(){ | ||
// build regex obj | ||
|
||
// var filterReduce = searchDictionary.get(savedOptions.options_locale).reduce(function(filtered, option) { | ||
// if (savedOptions.options_replacement_word.indexOf(option) == -1) { | ||
// filtered.push(option); | ||
// } | ||
// return filtered; | ||
// }, []); | ||
// searchDictionary.get(savedOptions.options_locale) | ||
|
||
if (savedOptions.options_enabled == false){ | ||
observer.disconnect(); | ||
return; | ||
} | ||
regexObj = new RegExp((savedOptions.options_match_custom_word == true ? savedOptions.options_matching_words.split(',') : searchDictionary.get(savedOptions.options_locale)).join('|'),"ig"); | ||
|
||
if (savedOptions.options_activation_on_pageload == true){ | ||
nodeTextReplace(document.body); | ||
} | ||
if (savedOptions.options_activation_on_interval == true){ | ||
initInterval(); | ||
} | ||
|
||
if (savedOptions.options_activation_on_change == true){ | ||
observer.observe(document.body, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
}else{ | ||
observer.disconnect(); | ||
} | ||
} | ||
|
||
if( document.readyState !== "loading") { | ||
preinit(); | ||
} else { | ||
document.addEventListener('DOMContentLoaded', function () { | ||
preinit(); | ||
}); | ||
} | ||
|
||
chrome.storage.onChanged.addListener(function(changes, namespace) { | ||
preinit(); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener( | ||
function(request, sender, sendResponse) { | ||
if (request.message == "marco") | ||
sendResponse({message: "polo"}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "Hodl", | ||
"version": "1.0.1", | ||
"description": "Follow the guiding principles of hodl by any means necessary.", | ||
"icons": { | ||
"16": "icons/icon-16.png", | ||
"48": "icons/icon-48.png", | ||
"128": "icons/icon-128.png" | ||
}, | ||
"permissions": [ | ||
"<all_urls>" , | ||
"tabs", | ||
"activeTab", | ||
"storage" | ||
], | ||
"browser_action": { | ||
"default_icon": "icons/icon-48.png", | ||
"default_title": "Hodl", | ||
"default_popup": "popup/options.html" | ||
}, | ||
"background": { | ||
"scripts": ["background.js"] | ||
} | ||
} |
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,31 @@ | ||
{ | ||
"applications": { | ||
"gecko": { | ||
"id": "[email protected]", | ||
"strict_min_version": "42.0" | ||
} | ||
}, | ||
"manifest_version": 2, | ||
"name": "Hodl", | ||
"version": "1.0.1", | ||
"description": "Follow the guiding principles of hodl by any means necessary.", | ||
"icons": { | ||
"16": "icons/icon-16.png", | ||
"48": "icons/icon-48.png", | ||
"128": "icons/icon-128.png" | ||
}, | ||
"permissions": [ | ||
"<all_urls>" , | ||
"tabs", | ||
"activeTab", | ||
"storage" | ||
], | ||
"browser_action": { | ||
"default_icon": "icons/icon-48.png", | ||
"default_title": "Hodl", | ||
"default_popup": "popup/options.html" | ||
}, | ||
"background": { | ||
"scripts": ["background.js"] | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.