From e07f717bc67c797f0717451de08edc484e9593f0 Mon Sep 17 00:00:00 2001 From: Juan Jose Date: Mon, 14 Nov 2016 13:20:31 -0500 Subject: [PATCH 1/3] Port exstension to safari --- Icon-64.png | Bin 0 -> 2529 bytes Info.plist | 81 ++++++++++++++++++++++++++++++++++++ data/bountysource_client.js | 28 ++++++++++++- data/get_safari_cookie.js | 3 ++ data/popup/application.js | 22 ++++++++++ data/popup/loader.js | 2 +- data/thumbs.js | 2 + global.html | 9 ++++ lib/bountysource_server.js | 63 ++++++++++++++++++++++++---- 9 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 Icon-64.png create mode 100644 Info.plist create mode 100644 data/get_safari_cookie.js create mode 100644 global.html diff --git a/Icon-64.png b/Icon-64.png new file mode 100644 index 0000000000000000000000000000000000000000..cd98beecb7d7b1e03725e3f213d7f835a620a4eb GIT binary patch literal 2529 zcmV<72_E)|P)`<0 z#uuo4IMu47ohmavMq9^9g&729Kt!Mdk+%fonV@+|-tX7V-rdtbKyA$3a5r~DY~lR5 z-@W(je$VguJ!eJY8$Xp?#6#gCAD0NY*a>i4sEH&JDZxM@<+ou+5duXBKp_5~2+#~2 zAtk;DFZqcXJ4ZxNsw zIx(t~g=qyW&YVec>NLiAVlDsA$>u7y)|RvSbQybFs}PDhYGepI(%^s*Am8ib!Ra?s zI(arI_Jx*~o>tyDzLnQbY^A!d9jBsxe+URjgB(vHFU(#_aoY4zH`fiPcCvimdsOzd z;SkE$5+J3)iu_XUD_nA6qn2Ut*U#3n{NQR78?0eO1jMQ?)-Qa7sY#g@7&GYB`f2KE z!>?;}^mh{<=_SJHCLzL$#}#Sm8BVv>Qo8XO>ik_{We>{)BswG6a`Th;VpE2_uh-wh zCtn@q)X{_K>S0mk89|3@Ksn3uGQcBz?c-pV%IG_i( z>4W9$ZL2w#N=KOhmr&WY=xNg9CYau{`Sc!MKlTw@>W?vi#Hpy3R!AZlFm$}Ci^Y=) zxi{~6@=~(RJwgw#@Pp;-Z?7GZC4@|X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 z6_r_uS^Oxgn9}TGqTEB%Vn*BqK3w=HSFd}*QtLY^E)b9gIm2v|o$5G)dY})yB{kz{L1UN3x2IBitAu&JzR5Zu<)#R_$X`^+9$toS?q113wZ~ zoXy@6FrHIx+kggciQraMOXwVLQvh=Wa&2^w};%M%g7yx z_7Komy#6W5TC2i7VPXpb0(kY*R$8?l?#Q~Dl8FVjek<_bV|VQl?%w(`&4GT~ULI`v zVB+f|tud;LImtOJ%ACm@UoI13$A|rZM;cD?`+cj}SbsFEf@f3-2qu#mhEB38nu3IM z3X`%ZO3o%LHkAp{iMX6@^SmF>INnynht&sJRk@R+oed+}QXf+ShFXXuU>F!u$0<}| z9BvX_Q6xr=`zDL{^#SU8+h`c*K{Irmio;e@AGItHTC5P~PM4icTRldAp8gK1`a6OI rRt2|u;XY@)^yTO!0xl77agYB1VFF*O_n0_)00000NkvXXu0mjf3)RSP literal 0 HcmV?d00001 diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..2091c7c --- /dev/null +++ b/Info.plist @@ -0,0 +1,81 @@ + + + + + Author + Bountysource + Builder Version + 11601.7.7 + CFBundleDisplayName + Bountysource + CFBundleIdentifier + com.bountysource.safari-extension + CFBundleInfoDictionaryVersion + 6.0 + CFBundleShortVersionString + 0.0.14 + CFBundleVersion + 1 + Chrome + + Database Quota + 1048576 + Global Page + global.html + Toolbar Items + + + Command + show_popover + Identifier + bountysource-button + Image + data/images/thumbsup-16.png + Include By Default + + Label + 👍 + Palette Label + Bountysource exstension + + + + Content + + Scripts + + End + + data/get_safari_cookie.js + data/thumbs.js + + Start + + data/bountysource_client.js + + + Stylesheets + + data/stylesheets/thumbs.css + + + Description + Bountysource Browser Extension + DeveloperIdentifier + 0000000000 + ExtensionInfoDictionaryVersion + 1.0 + Permissions + + Website Access + + Include Secure Pages + + Level + All + + + Website + https://www.bountysource.com + + diff --git a/data/bountysource_client.js b/data/bountysource_client.js index 1223c41..0bdd5ba 100644 --- a/data/bountysource_client.js +++ b/data/bountysource_client.js @@ -1,6 +1,6 @@ // Cross-browser helpers to be used in popups and content-scripts var BountysourceClient = { - browser: typeof(chrome)!=='undefined' ? 'chrome' : 'firefox', + browser: typeof(chrome)!=='undefined' ? 'chrome' : typeof(safari)!=='undefined' ? 'safari' : 'firefox', // Computes path to extension hosted image imagePath: function(image) { @@ -8,6 +8,8 @@ var BountysourceClient = { return chrome.extension.getURL('data/images/' + image); } else if (self && self.options && self.options.image_base) { return self.options.image_base + image; + } else if (window.safari) { + return safari.extension.baseURI + 'data/images/' + image; } }, @@ -26,6 +28,30 @@ var BountysourceClient = { options.callback_str = "callback_" + (new Date()).getTime(); self.port.once(options.callback_str, callback); self.port.emit("message", options); + } else if (BountysourceClient.browser === 'safari') { + // Check if is sending from popover or normal page + if (safari.self.tab) { + // Is normal page + // Equivalent code of self.port.once + options.callback_str = "callback_" + (new Date()).getTime(); + var handler = function(event) { + if (event.name === options.callback_str) { + callback(event.message); + safari.self.removeEventListener('message', handler); + } + } + safari.self.addEventListener('message', handler, false); + safari.self.tab.dispatchMessage('message', options); + } else { + // Is popover + var BountysourceServer = safari.extension.globalPage.contentWindow.BountysourceServer; + BountysourceServer.get_access_token(function(access_token) { + options.access_token = access_token; + options.callback = callback; + + BountysourceServer[options.action](options); + }); + } } }, diff --git a/data/get_safari_cookie.js b/data/get_safari_cookie.js new file mode 100644 index 0000000..add318c --- /dev/null +++ b/data/get_safari_cookie.js @@ -0,0 +1,3 @@ +if (document.location.host === 'www.bountysource.com') { + safari.self.tab.dispatchMessage('cookie', document.cookie); +} \ No newline at end of file diff --git a/data/popup/application.js b/data/popup/application.js index aca52ab..9e09929 100644 --- a/data/popup/application.js +++ b/data/popup/application.js @@ -5,6 +5,8 @@ var BountysourcePopup = { BountysourcePopup.setupTabHandlers(); BountysourcePopup.setupFeedbackForm(); BountysourcePopup.loadThumbs(); + BountysourcePopup.setupLinks(); + BountysourcePopup.setupForms(); }, loadCurrentPerson: function() { @@ -12,6 +14,7 @@ var BountysourcePopup = { BountysourceClient.api({ path: 'people/me' }, function(response) { + console.log("Call back"); if (response.id) { // nav document.querySelector('#person-info-profile-link').classList.remove('hide'); @@ -122,6 +125,7 @@ var BountysourcePopup = { document.querySelector('#thumbs-message-none').classList.remove('hide'); } + BountysourcePopup.setupLinks(); BountysourcePopup.resizePopup(); }); }, @@ -183,6 +187,24 @@ var BountysourcePopup = { document.querySelector('#feedback-form').classList.add('hide'); BountysourcePopup.resizePopup(); }); + }, + + setupLinks: function() { + if ((typeof(safari) !== 'undefined')) { + var links = document.querySelectorAll('a[target="_blank"]'); + for (var i = 0; i < links.length; i++) { + links[i].removeAttribute('target'); + } + } + }, + + setupForms: function() { + if ((typeof(safari) !== 'undefined')) { + var links = document.querySelectorAll('form[target="_blank"]'); + for (var i = 0; i < links.length; i++) { + links[i].removeAttribute('target'); + } + } } }; diff --git a/data/popup/loader.js b/data/popup/loader.js index 18f5161..885be5a 100644 --- a/data/popup/loader.js +++ b/data/popup/loader.js @@ -3,7 +3,7 @@ (function() { var scripts = ['../bountysource_client.js', 'application.js']; - if (typeof(chrome) !== 'undefined') { + if (typeof(chrome) !== 'undefined' || typeof(safari) !== 'undefined') { for (var i=0; i < scripts.length; i++) { var script_tag = document.createElement('script'); script_tag.src = scripts[i]; diff --git a/data/thumbs.js b/data/thumbs.js index bb03932..c106719 100644 --- a/data/thumbs.js +++ b/data/thumbs.js @@ -132,6 +132,7 @@ downvote: !!this.api_response.has_thumbed_up }, }, function(response) { + debugger; if (!response) { console.log("ERROR5", response); this.setInfoBox('ERR5', 'https://github.com/bountysource/browser-extension/issues/22'); @@ -151,6 +152,7 @@ var matches; // Bountysource + //debugger; if (document.location.host.match(/\.bountysource\.com$/)) { document.body.classList.add('bountysource-thumbs-extension-is-installed'); diff --git a/global.html b/global.html new file mode 100644 index 0000000..9ceedda --- /dev/null +++ b/global.html @@ -0,0 +1,9 @@ + + + + global HTML page + + + + + \ No newline at end of file diff --git a/lib/bountysource_server.js b/lib/bountysource_server.js index 39bc55d..de10f5b 100644 --- a/lib/bountysource_server.js +++ b/lib/bountysource_server.js @@ -9,7 +9,7 @@ if (typeof(localStorage) === 'undefined') { // global functions var BountysourceServer = { - browser: typeof(chrome)!=='undefined' ? 'chrome' : 'firefox', + browser: typeof(chrome)!=='undefined' ? 'chrome' : typeof(safari)!=='undefined' ? 'safari' : 'firefox', www_base: 'https://www.bountysource.com/', api_base: 'https://api.bountysource.com/', @@ -64,6 +64,24 @@ var BountysourceServer = { }); } }); + } else if (BountysourceServer.browser === 'safari') { + safari.application.addEventListener('message', function(event) { + if (event.name === 'message') { + BountysourceServer.get_access_token(function(access_token) { + var options = event.message; + options.access_token = access_token; + + // turn callback_str into function + options.callback = function(response) { + event.target.page.dispatchMessage(options.callback_str, response); + }; + + BountysourceServer[options.action](options); + }); + } else if (event.name === 'cookie') { + localStorage['safari_cookie'] = event.message; + } + }, false); } }, @@ -123,6 +141,26 @@ var BountysourceServer = { } } }); + } else if (BountysourceServer.browser === 'safari') { + safari.application.addEventListener('command', function(event) { + if (event.command === 'show_popover') { + var button; + for (var i = 0; i < safari.extension.toolbarItems.length; i++) { + if (safari.extension.toolbarItems[i].identifier === 'bountysource-button') { + button = safari.extension.toolbarItems[i]; + } + } + if (button.popover) { + button.popover.hide(); + button.popover = null; + safari.extension.removePopover('bountysource-popover'); + } + + popover = safari.extension.createPopover('bountysource-popover', safari.extension.baseURI + 'data/popup/application.html', 420); + button.popover = popover; + button.showPopover(); + } + }, false); } }, @@ -195,13 +233,10 @@ var BountysourceServer = { var cookieUri = ios.newURI(BountysourceServer.www_base, null, null); var cookieSvc = ff_chrome.components.classes["@mozilla.org/cookieService;1"].getService(ff_chrome.components.interfaces.nsICookieService); var cookie = cookieSvc.getCookieString(cookieUri, null); - var cookies = (cookie || '').split('; '); - for (var i=0; i < cookies.length; i++) { - var regex_match = cookies[i].match(/^v2_access_token=(.*)$/); - if (regex_match) { - callback(JSON.parse(decodeURIComponent(regex_match[1]))); - return; - } + callback(BountysourceServer.get_access_token_from_cookie(cookie)); + } else if (BountysourceServer.browser === 'safari') { + if (localStorage['safari_cookie']) { + callback(BountysourceServer.get_access_token_from_cookie(localStorage['safari_cookie'])); } callback(null); } @@ -214,6 +249,7 @@ var BountysourceServer = { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { + console.log("Call callback for path: ", options.request.path); options.callback(xhr.status === 200 ? JSON.parse(xhr.responseText) : null); } }; @@ -261,6 +297,17 @@ var BountysourceServer = { }); xhr.open('GET', path, true); xhr.send(); + }, + + get_access_token_from_cookie: function(cookie) { + var cookies = (cookie || '').split('; '); + for (var i=0; i < cookies.length; i++) { + var regex_match = cookies[i].match(/^v2_access_token=(.*)$/); + if (regex_match) { + return JSON.parse(decodeURIComponent(regex_match[1])); + } + } + return null; } }; From a0b16971396125e8a30d0b20f51c41bb8715e0b1 Mon Sep 17 00:00:00 2001 From: Juan Jose Date: Mon, 14 Nov 2016 13:28:58 -0500 Subject: [PATCH 2/3] Remove extra debug. --- data/popup/application.js | 1 - data/thumbs.js | 2 -- lib/bountysource_server.js | 1 - 3 files changed, 4 deletions(-) diff --git a/data/popup/application.js b/data/popup/application.js index 9e09929..bd4ed52 100644 --- a/data/popup/application.js +++ b/data/popup/application.js @@ -14,7 +14,6 @@ var BountysourcePopup = { BountysourceClient.api({ path: 'people/me' }, function(response) { - console.log("Call back"); if (response.id) { // nav document.querySelector('#person-info-profile-link').classList.remove('hide'); diff --git a/data/thumbs.js b/data/thumbs.js index c106719..bb03932 100644 --- a/data/thumbs.js +++ b/data/thumbs.js @@ -132,7 +132,6 @@ downvote: !!this.api_response.has_thumbed_up }, }, function(response) { - debugger; if (!response) { console.log("ERROR5", response); this.setInfoBox('ERR5', 'https://github.com/bountysource/browser-extension/issues/22'); @@ -152,7 +151,6 @@ var matches; // Bountysource - //debugger; if (document.location.host.match(/\.bountysource\.com$/)) { document.body.classList.add('bountysource-thumbs-extension-is-installed'); diff --git a/lib/bountysource_server.js b/lib/bountysource_server.js index de10f5b..3d71992 100644 --- a/lib/bountysource_server.js +++ b/lib/bountysource_server.js @@ -249,7 +249,6 @@ var BountysourceServer = { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { - console.log("Call callback for path: ", options.request.path); options.callback(xhr.status === 200 ? JSON.parse(xhr.responseText) : null); } }; From ba53bba1da8f417f92d803002908842675b5aca4 Mon Sep 17 00:00:00 2001 From: Juan Jose Date: Thu, 17 Nov 2016 16:36:54 -0500 Subject: [PATCH 3/3] Fix doble callback --- lib/bountysource_server.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/bountysource_server.js b/lib/bountysource_server.js index 3d71992..ad13fc4 100644 --- a/lib/bountysource_server.js +++ b/lib/bountysource_server.js @@ -235,10 +235,7 @@ var BountysourceServer = { var cookie = cookieSvc.getCookieString(cookieUri, null); callback(BountysourceServer.get_access_token_from_cookie(cookie)); } else if (BountysourceServer.browser === 'safari') { - if (localStorage['safari_cookie']) { - callback(BountysourceServer.get_access_token_from_cookie(localStorage['safari_cookie'])); - } - callback(null); + callback(BountysourceServer.get_access_token_from_cookie(localStorage['safari_cookie'] || null)); } },