Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Update 1.3.1
Browse files Browse the repository at this point in the history
Fixed several bugs and made internal changes to conform to Firefox's
add-on quality requirements
  • Loading branch information
NIX committed Apr 7, 2015
1 parent bdb5318 commit 976b829
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 59 deletions.
8 changes: 4 additions & 4 deletions Firefox/data/js/jquery2.js

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions Firefox/data/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ self.port.once("translation", function(response) {
var translation = response.translation;
//../locales/es/logo.png
$("#logo").css("background-image", "url('./locales/" + translation.lang + "/logo.png')");
main(response.data, translation, response.usage);
main(response.data, translation, response.usage, response.addonVersion);
});

function main(ExtensionData, translation, usage) {
function main(ExtensionData, translation, usage, addonVersion) {
//dom elements
var fieldAdd = $('#add-field');
var btnAdd = $('#btn-add');
Expand Down Expand Up @@ -302,7 +302,7 @@ function main(ExtensionData, translation, usage) {
//})();
var blob = new Blob([
"──────────────────────────────────────────────────────────────────────\n\n",
"My Youtube Beta 3\n\n",
"My Youtube " + addonVersion + "\n\n",
"THIS FILE CONTAINS YOUR MY-YOTUBE SETTINGS\n",
"THIS INFORMATION IS NOT ENCRYPTED, IT CAN BE EASILY READ\n",
"SAVE IT IN A SAFE PLACE OR DELETE IT WHEN NO LONGER NEEDED\n\n",
Expand All @@ -311,12 +311,13 @@ function main(ExtensionData, translation, usage) {
//'<MyYoutube key="' + (!config.user_config.in_key ? 'ASK' : psw) + '">',
'<MyYoutube>',
//Tea.encrypt(data, psw),
btoa(data),
utf8_to_b64(data),
"</MyYoutube>"
], {
type: "text/plain;charset=utf-8"
});
unsafeWindow.saveAs(blob, "MyYoutube.settings");

unsafeWindow.saveAs(cloneInto(blob, unsafeWindow), "MyYoutube.settings");

//if (!config.user_config.in_key) {
// $('#key').text(psw);
Expand Down Expand Up @@ -358,7 +359,7 @@ function main(ExtensionData, translation, usage) {
// key = prompt('Escribe tu llave de encriptacion');
//}
settings = data[1];
settings = atob(settings);
settings = b64_to_utf8(settings);
try {
settings = JSON.parse(settings);
} catch (e) {
Expand All @@ -376,4 +377,17 @@ function main(ExtensionData, translation, usage) {
reader.readAsText(file);
});
}

/*
In most browsers, calling window.btoa() on a Unicode string will cause a Character Out Of Range exception
see: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
*/

function utf8_to_b64(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}

function b64_to_utf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}
}
36 changes: 24 additions & 12 deletions Firefox/data/js/youtubeMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,46 @@ self.port.once("channels", function(channels) {
break;
}
}

//"add youtuber" button
var addBtn = document.createElement('button');
addBtn.setAttribute('class', 'yt-uix-button yt-uix-button-size-default yt-uix-button-has-icon yt-uix-button-subscribe-branded');
addBtn.setAttribute('style', 'background-image: linear-gradient(to top, rgba(199, 26, 166, 1) 0px, rgba(230, 34, 200, 1) 100%); margin-right: 12px;');

var btnTxt = document.createElement('span');
btnTxt.setAttribute('style', 'margin-left:5px;');
//"add youtuber" button span elem
var addBtnSpanEl = document.createElement('span');
addBtnSpanEl.setAttribute('style', 'margin-left:5px;');
//"add youtuber" button text
var addBtnTxt;

if (isNewYoutuber) {
btnTxt.innerHTML = self.options.btnAddTxt;
addBtnTxt = document.createTextNode(self.options.btnAddTxt);
addBtn.addEventListener('click', addYoutuber);
} else {
btnTxt.innerHTML = self.options.btnAddedTxt;
addBtnTxt = document.createTextNode(self.options.btnAddedTxt);
addBtn.setAttribute('disabled', 'disabled');
}
addBtn.appendChild(btnTxt);
addBtnSpanEl.appendChild(addBtnTxt);
addBtn.appendChild(addBtnSpanEl);

var containerClass = onWatchPage ? '' : ' with-preferences';
var container = document.getElementsByClassName('yt-uix-button-subscription-container' + containerClass)[0];
var susBtn = container.getElementsByTagName('button')[0];
container.insertBefore(addBtn, susBtn);

function addYoutuber() {
if (document.getElementById('myY-modal')) {
document.getElementById('myY-modal').setAttribute('style', '');
var modal = document.getElementById('myY-modal');
if (modal) {
modal.setAttribute('style', '');
} else {
var modal = document.createElement('div');
modal = document.createElement('div');
modal.setAttribute('class', 'modal');
modal.setAttribute('id', 'myY-modal');
modal.innerHTML = '<div style="font-weight: bolder">' + self.options.btnAddingTxt + '...</div>';

var modalContent = document.createElement('div');
modalContent.setAttribute('style', 'font-weight: bolder');
modalContent.textContent = self.options.btnAddingTxt;

modal.appendChild(modalContent);
document.body.appendChild(modal);
}

Expand All @@ -66,9 +76,11 @@ self.port.once("channels", function(channels) {
if (status.isError === false) {
addBtn.setAttribute('disabled', 'disabled');
addBtn.removeEventListener('click', addYoutuber, false);
btnTxt.innerHTML = self.options.btnAddedTxt;


addBtnSpanEl.textContent = self.options.btnAddedTxt;
} else {
alert(self.options.errMsg);
window.alert(self.options.errMsg);
}

//remove/hide
Expand Down
76 changes: 41 additions & 35 deletions Firefox/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@
This is the brain file of the extension
it is akin to background.js in chrome extensions
*/
const tmr = require("sdk/timers");
var tmr = require("sdk/timers");
tmr.setTimeout(function() {

const SS = require("sdk/simple-storage"); //simple storage
const DATABASE = require("./Mi_Youtube_Data_2"); //import data module
//create data object (constains all extension data)
const DATA = new DATABASE.MY_YOUTUBE_DATA(SS.storage);
var SS = require("sdk/simple-storage"); //simple storage
var DATABASE = require("./Mi_Youtube_Data_2"); //import data module
//create data object (varains all extension data)
var DATA = new DATABASE.MY_YOUTUBE_DATA(SS.storage);
//we want the user's FF version for version-dependent features
var FF_VERSION = parseInt(require("sdk/system").version);
//todo - inform user he's using too much info
//SS.on("OverQuota", function() {
//window.alert('Storage limit exceeded');
//});

DATA.load(function(ExtensionData) {
//---------required modules & setup -------------------------------
//const {ActionButton} = require("sdk/ui/button/action"); //button ui
const {
//var {ActionButton} = require("sdk/ui/button/action"); //button ui
var {
ToggleButton
} = require('sdk/ui/button/toggle');
const {
var {
Panel
} = require("sdk/panel"); //panel (for main popup)
const Request = require("sdk/request").Request; //network requests
const tabs = require("sdk/tabs");
const translate = require("sdk/l10n").get;
const notifications = require("sdk/notifications");
const pageMod = require("sdk/page-mod"); //needed to add contentscripts
const self = require("sdk/self");
var Request = require("sdk/request").Request; //network requests
var tabs = require("sdk/tabs");
var translate = require("sdk/l10n").get;
var notifications = require("sdk/notifications");
var pageMod = require("sdk/page-mod"); //needed to add contentscripts
var self = require("sdk/self");

const optionsURL = "options.html";
var optionsURL = "options.html";

//first install
if (ExtensionData.isNewInstall) {
Expand All @@ -58,30 +60,26 @@ tmr.setTimeout(function() {
translations['contextMenu'] = translate('contextMenu');
translations['uploadedBy'] = translate('uploadedBy');

for (let i = 0; i <= 3; i++) {
let name = "popupE" + i + "_B";
let name2 = "popupE" + i + "_H";
for (var i = 0; i <= 3; i++) {
var name = "popupE" + i + "_B";
var name2 = "popupE" + i + "_H";

translations[name] = translate(name);
translations[name2] = translate(name2);
};
}

//----------create extension main button & popup setup--------------------------------
var mainWindow; //main popup window
//creates the main extension button
var mainBtn = ToggleButton({
id: "mainBtn",
label: "My Youtube",
badge: '',
icon: {
"16": "./icons/icon16.png", //paths relative to the data folder
"38": "./icons/icon38.png",
"48": "./icons/icon48.png"
},
//onClick: function (state) {
//create and initialize the main popup window
//initializeMainwindow();
//mainWindow.show();
//}
onChange: function(state) {
if (state.checked) {
initializeMainwindow();
Expand Down Expand Up @@ -170,7 +168,7 @@ tmr.setTimeout(function() {
],
//port event listeners
onAttach: function(worker) {
let translation = {};
var translation = {};
//listen for translation request
worker.port.once("translation", function(strings) {
for (var i = 0; i < strings.length; i++) {
Expand All @@ -182,7 +180,8 @@ tmr.setTimeout(function() {
data: ExtensionData,
translation: translation,
usage: SS.quotaUsage,
optionsURL: optionsURL
optionsURL: optionsURL,
addonVersion: self.version
});
});

Expand All @@ -200,7 +199,7 @@ tmr.setTimeout(function() {

//------Setup alarm------------------------------------------
if (ExtensionData.prefs['play_popup_sound']) {
const alarm = require("sdk/page-worker")
var alarm = require("sdk/page-worker")
.Page({
contentScript: "self.port.on('playAlarm', function() {document.getElementById('alarm').play();});",
contentScriptWhen: "ready",
Expand Down Expand Up @@ -277,7 +276,12 @@ tmr.setTimeout(function() {
} else {
//show popup letting user know of new videos
if ((totalNewVideos > 0) && (oldVideosHash !== newVideosHash)) {
mainBtn.icon = "./icons/badges/" + (totalNewVideos > 9 ? 10 : totalNewVideos) + ".png";
if (FF_VERSION >= 36) {
mainBtn.badge = totalNewVideos;
} else {
mainBtn.icon = "./icons/badges/" + (totalNewVideos > 9 ? 10 : totalNewVideos) + ".png";
}

//ExtensionData.cache = []; //clean cache
ExtensionData.cache = newVideos; //THIS WE WANT! - save new videos found
oldVideosHash = newVideosHash;
Expand Down Expand Up @@ -305,10 +309,10 @@ tmr.setTimeout(function() {
function getYoutuber(account, callback, getVideos) {
var url = 'http://gdata.youtube.com/feeds/api/users/' + account;
var params = {
"v": 2,
"alt": 'json'
}
//extra parameters needed to get account videos
"v": 2,
"alt": 'json'
};
//extra parameters needed to get account videos
if (getVideos) {
url += '/uploads';
params['start-index'] = 1;
Expand Down Expand Up @@ -433,8 +437,10 @@ tmr.setTimeout(function() {

//update badge
mainWindow.port.on("updateBadge", function() {
if (mainBtn.icon.indexOf("badges") !== -1) {
let newIcon = mainBtn.icon.replace(/^\D+/g, '');
if (FF_VERSION >= 36) {
mainBtn.badge = (mainBtn.badge - 1) > 0 ? mainBtn.badge - 1 : '';
} else if (mainBtn.icon.indexOf("badges") !== -1) {
var newIcon = mainBtn.icon.replace(/^\D+/g, '');
newIcon = parseInt(newIcon) - 1;
if (newIcon > 0)
mainBtn.icon = "./icons/badges/" + newIcon + ".png";
Expand Down Expand Up @@ -472,7 +478,7 @@ tmr.setTimeout(function() {
}

function notify(num) {
var notificationText = num
var notificationText = num;
if (translate('lang') === 'es') {
if (num > 1)
notificationText += ' nuevos videos han sido subidos';
Expand Down
Binary file modified Firefox/my-youtube.xpi
Binary file not shown.
3 changes: 1 addition & 2 deletions Firefox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
"description": "Never miss another video of your favorite Youtubers",
"author": "Juanix.net",
"license": "GNU V2",
"version": "1.3.0.2",
"version": "1.3.1",

"icon": "data//icons//icon48.png",
"permissions": {
"unsafe-content-script": true,
"cross-domain-content": [
"http://*.youtube.com/*",
"https://*.youtube.com/*"
Expand Down

0 comments on commit 976b829

Please sign in to comment.