1
Fork 0

Added images locally, and modified build process

This commit is contained in:
Jake Howard 2015-08-24 17:54:23 +01:00
parent 0fd819faae
commit 29161fc565
11 changed files with 72 additions and 89 deletions

BIN
assets/allthethings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

25
assets/build-assets.py Normal file
View file

@ -0,0 +1,25 @@
import json, os
from base64 import b64encode
from glob import glob
def get_filename(path):
return path.replace('assets/', "").replace('.png', '')
files = glob('assets/*.png')
image_bin = []
for filename in files:
with open(filename, 'rb') as file:
image_bin.append({ get_filename(filename): "data:image/png;base64,"+ (str(b64encode(file.read()))[2:-1])})
image_decoder = {"sites":image_bin}
image_decoder_json = json.dumps(image_decoder, indent=2, sort_keys=True)
js_file = None
with open('src/image-decoder.js', "r") as file:
js_file = file.read()
js_file = js_file.replace("%image_decoder%", image_decoder_json)
with open('build/image-decoder.js', 'w') as file:
file.write(js_file)

BIN
assets/noot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

@ -1,8 +1,10 @@
#!/usr/bin/bash
cp -r src/* build/
cp -r src/lib/* build/lib/
cp -r src/decoder.json build/
rm -rf build/injections/*
mkdir -p build/src/injections
for f in src/injections/*; do uglifyjs "src/image-decoder.js" "src/lib/jquery.js" $f --compress --screw-ie8 --define --stats --keep-fnames -o build/$f; done
uglifyjs build/image-decoder.js --compress --screw-ie8 --define --keep-fnames -o build/image-decoder.js
for f in src/injections/*; do uglifyjs "build/image-decoder.js" "src/lib/jquery.js" $f --compress --screw-ie8 --define --stats --keep-fnames -o build/$f; done
cp -rp build/src/* build/
rm -rf build/src

View file

@ -2,21 +2,14 @@ var self = require('sdk/self');
var pageMod = require("sdk/page-mod");
var sites = require("data/decoder.json").sites;
patterns = []
for (var i = 0; i < sites.length; i++) {
patterns.push(Object.keys(sites[i])[0])
}
site = Object.keys(sites[i]);
script = sites[i][site];
site = '*.' + site;
console.log("SS: " + site + " " + script);
pageMod.PageMod({
include: '*',
contentScriptFile: './../injector.js',
attachTo: 'top',
onAttach: function(worker) {
worker.port.emit('init');
},
contentScriptOptions: {
injectorURL: self.data.url('injections/'),
sites: require('data/decoder.json').sites,
}
include: site,
contentScriptFile: './injections/' + script,
attachTo: ['top', 'existing', 'iframe'],
});
}

View file

@ -1,18 +0,0 @@
var injection_script = document.createElement('script');
injection_script.type = 'text/javascript';
sites = JSON.parse(self.options.sites);
console.log(sites);
console.log(sites[document.domain]);
if (self.options.sites.hasOwnProperty(document.domain)) {
self.port.on('init',function() {
injection_script.src=(self.options.injectorURL + self.options.site[document.domain]);
window.document.body.appendChild(injection_script);
});
console.log("Injector Imported");
} else {
console.log('No script');
}

View file

@ -10,9 +10,10 @@
"build-chrome": "crx pack chrome -o chrome/hipchat-emoticons-for-all.crx -p chrome/key.pem",
"test-firefox": "cd firefox/ && jpm run -b /usr/bin/firefox && cd -",
"build-js": "bash build-js.sh",
"build-assets": "python assets/build-assets.py",
"build-data-files": "python firefox/build-package.py && python chrome/build-manifest.py",
"distribute": "rm -rf firefox/data/* chrome/data/* && cp -rf build/* firefox/data/ && cp -rf build/* chrome/data/",
"build": "npm run create-dirs && npm run build-js && npm run distribute && npm run build-data-files && npm run build-extensions",
"build": "npm run create-dirs && npm run build-assets && npm run build-js && npm run distribute && npm run build-data-files && npm run build-extensions",
"clean": "rm -rf firefox/data chrome/data node_modules/ build/"
},
"repository": {

View file

@ -1,3 +1,15 @@
window.image_decoder = {
"remember" : "https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/23362/noot-1438871175.png"
function inject_image(ident, classes) {
classes = classes || "";
$(ident).each(function() {
for (var i = 0; i < image_decoder.length; i++) {
key = Object.keys(image_decoder[i]);
image = image_decoder[key];
$(this).html($(this).html().replace(
key,
"<img class='" + classes + "' style='height: 30px; width: 30px;' src='" + image + "'/>"
));
}
});
}
var image_decoder = %image_decoder%

View file

@ -1,7 +1,8 @@
var jq = jQuery.noConflict(true);
function change_chat_tabs() {
console.log("Event");
inject_image('._d97');
jq('._d97').each(function(){
for (var i = 0; i < image_decoder.length; i++) {
console.log('Checking for ' + image_decoder[i][0])
@ -40,4 +41,3 @@ jq('._552m').on('input paste', function() { // Text change in textbox. Mainly u
change_chat_tabs();
alert("Facebook");

View file

@ -1,37 +1,11 @@
var jq = jQuery.noConflict(true);
function get_images() {
return JSON.parse('[{"(noot)" : "https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/23362/noot-1438871175.png"}]');
}
function change_comments() {
window.image_decoder = get_images();
console.log("comment event");
jq('.comment-body').each(function() {
for (var i = 0; i < window.image_decoder.length; i++) {
key = Object.keys(window.image_decoder[i]);
image = window.image_decoder[key];
console.log('Checking for ' + key)
jq(this).html(jq(this).html().replace(
key,
"<img style='height: 30px; width: 30px;' src='" + image + "'/>"
));
}
});
inject_image('.comment-body');
}
function change_readme() {
window.image_decoder = get_images();
console.log("readme event");
for (var i = 0; i < window.image_decoder.length; i++) {
key = Object.keys(window.image_decoder[i]);
image = window.image_decoder[i][key];
console.log('Checking for ' + key)
jq('#readme').html(jq('#readme').html().replace(
key,
"<img style='height: 30px; width: 30px;' src='" + image + "'/>"
));
}
inject_image('.comment-body');
}
@ -46,11 +20,5 @@ jq('.js-comment-container').on('load change', function(){ // when another comme
});
window.setInterval(function(){
change_comments();
change_readme();
}, 3000);
alert("Github");