[WIP] MSEdge #191

Open
wants to merge 1 commit into
from
View
@@ -3,6 +3,7 @@
"version": "2.4.3",
"dependencies": {
"bowser": "^1.3.0",
+ "chrome-browser-object-polyfill": "^0.2.0",
"delegate": "^3.0.0",
"dom-css": "^2.0.0",
"jquery": "^2.1.4",
@@ -21,9 +22,10 @@
},
"scripts": {
"test": "standard \"./**/*.js\" && ava",
- "build": "npm run build-chrome && npm run build-firefox",
+ "build": "npm run build-chrome && npm run build-firefox && npm run build-edge",
"build-chrome": "mkdir -p dist/chrome && rm -rf dist/chrome/* && script/generate_manifest && cp -r src/statics/* dist/chrome && browserify src/normal/index.js -o dist/chrome/main.js && browserify src/common/content/content.js -o dist/chrome/content.js",
"build-firefox": "mkdir -p dist/firefox && rm -rf dist/firefox/* && TARGET=firefox script/generate_manifest && wemf dist/firefox/manifest.json -U && cp -r src/statics/* dist/firefox && browserify src/normal/index.js -o dist/firefox/main.js && browserify src/common/content/content.js -o dist/firefox/content.js",
+ "build-edge": "mkdir -p dist/edge && rm -rf dist/edge/* && TARGET=edge script/generate_manifest && cp -r src/statics/* dist/edge && browserify src/normal/index.js -o dist/edge/main.js && browserify src/common/content/content.js -o dist/edge/content.js",
"pack": "npm run pack-chrome && npm run pack-firefox",
"pack-chrome": "npm run build-chrome && crx pack ./dist/chrome --zip-output ./build/chrome.zip -o ./build/chrome.crx",
"pack-firefox": "npm run build-firefox && web-ext build -a build -s dist/firefox -v"
@@ -2,6 +2,8 @@
var manifest = require('../src/manifest.json')
if (process.env.TARGET === 'firefox') {
var manifestPath = '../dist/firefox/manifest.json'
+} else if (process.env.TARGET === 'edge') {
+ var manifestPath = '../dist/edge/manifest.json'
} else {
var manifestPath = '../dist/chrome/manifest.json'
}
@@ -1,9 +1,10 @@
(function () {
+ require('chrome-browser-object-polyfill')
if (window.__embededGyazoContentJS) {
return
}
window.__embededGyazoContentJS = true
- const browser = require('bowser')
+ const browserInfo = require('bowser')
const storage = require('../libs/storageSwitcher')
const ESC_KEY_CODE = 27
const JACKUP_HEIGHT = 30
@@ -125,11 +126,15 @@
} else {
const loadingElm = document.createElement('span')
loadingElm.className = 'gyazo-spin'
- window.fetch(chrome.runtime.getURL('imgs/spinner.svg'))
- .then((res) => res.text())
- .then((text) => {
- loadingElm.innerHTML = text
- })
+ try {
+ window.fetch(chrome.runtime.getURL('imgs/spinner.svg'))
+ .then((res) => res.text())
+ .then((text) => {
+ loadingElm.innerHTML = text
+ })
+ } catch(e) {
+ loadingElm.innerHTML = `<img src='${chrome.runtime.getURL('imgs/spinner.svg')}' />`
+ }
showImage.appendChild(loadingElm)
}
notificationContainer.innerHTML = ''
@@ -173,10 +178,15 @@
let iconElm = document.createElement('div')
iconElm.classList.add('gyazo-button-icon')
-
- window.fetch(chrome.runtime.getURL(`imgs/${loadSvgName}.svg`))
- .then((res) => res.text())
- .then((text) => iconElm.innerHTML = text)
+ try {
+ //Edge cannot fetch to ms-edge-extension:
+ window.fetch(chrome.runtime.getURL(`imgs/${loadSvgName}.svg`))
+ .then((res) => res.text())
+ .then((text) => iconElm.innerHTML = text)
+ } catch (e) {
+ const svgUrl = chrome.runtime.getURL(`imgs/${loadSvgName}.svg`)
+ iconElm.innerHTML = `<img src='${svgUrl}' />`
+ }
let textElm = document.createElement('div')
textElm.className = 'gyazo-button-text'
@@ -199,9 +209,13 @@
const closeBtnIcon = document.createElement('div')
closeBtnIcon.className = 'gyazo-menu-element gyazo-icon gyazo-icon-cross'
closeBtn.appendChild(closeBtnIcon)
- window.fetch(chrome.runtime.getURL('imgs/cross.svg'))
- .then((res) => res.text())
- .then((text) => closeBtnIcon.innerHTML = text)
+ try {
+ window.fetch(chrome.runtime.getURL('imgs/cross.svg'))
+ .then((res) => res.text())
+ .then((text) => closeBtnIcon.innerHTML = text)
+ } catch (e) {
+ closeBtnIcon.innerHTML = `<img src='${chrome.runtime.getURL('imgs/cross.svg')}' />`
+ }
closeBtn.setAttribute('title', 'Press: Escape')
window.addEventListener('contextmenu', function (event) {
@@ -464,7 +478,7 @@
action: 'gyazoCaptureWithSize',
data: data,
tab: request.tab
- }, null, function () {
+ }, function () {
restoreFixedElement()
document.body.removeChild(jackup)
unlockScroll(overflow)
@@ -629,7 +643,7 @@
action: 'gyazoCaptureWithSize',
data: data,
tab: request.tab
- }, null, function () {
+ }, function () {
document.body.removeChild(jackup)
unlockScroll(overflow)
restoreFixedElement()
@@ -665,7 +679,7 @@
action: 'gyazoCaptureWithSize',
data: data,
tab: request.tab
- }, null, function () {
+ }, function () {
document.body.removeChild(jackup)
unlockScroll(overflow)
})
@@ -677,6 +691,6 @@
return true
})
// XXX: Firefox can't embed moz-extension:// file in content
- if (browser.firefox) return
+ if (browserInfo.firefox) return
require('./expander')
})()
@@ -1,3 +1,4 @@
+require('chrome-browser-object-polyfill')
const delegate = require('delegate')
const css = require('dom-css')
const extend = require('xtend')
@@ -1,4 +1,5 @@
-const browser = require('bowser')
+require('chrome-browser-object-polyfill')
+const browserInfo = require('bowser')
module.exports = class UploadNotification {
constructor (tabId) {
@@ -12,7 +13,7 @@ module.exports = class UploadNotification {
finish (imagePageUrl, imageDataUrl, callback) {
this.update({
title: chrome.i18n.getMessage('uploadingFinishTitle'),
- message: browser.firefox ? '' : chrome.i18n.getMessage('uploadingFinishMessage'),
+ message: browserInfo.firefox ? '' : chrome.i18n.getMessage('uploadingFinishMessage'),
imagePageUrl: imagePageUrl,
imageUrl: imageDataUrl,
isFinish: true
@@ -1,6 +1,7 @@
// Firefox WebExtension doesn't have chrome.storage.sync but only chrome.storage.local
// https://bugzilla.mozilla.org/show_bug.cgi?id=1213475
// https://bugzilla.mozilla.org/show_bug.cgi?id=1220494
+require('chrome-browser-object-polyfill')
try {
module.exports = ('sync' in chrome.storage && typeof chrome.storage.sync === 'function')
? chrome.storage.sync
View
@@ -9,6 +9,7 @@
"notifications",
"contextMenus",
"tabs",
+ "cookies",
"clipboardWrite",
"clipboardRead",
"storage"
View
@@ -1,5 +1,7 @@
+require('chrome-browser-object-polyfill')
+
const $ = require('jquery')
-const browser = require('bowser')
+const browserInfo = require('bowser')
const UploadNotification = require('../common/libs/UploadNotification')
const saveToClipboard = require('../common/libs/saveToClipboard')
const canvasUtils = require('../common/libs/canvasUtils')
@@ -32,6 +34,9 @@ function postToGyazo (tabId, data) {
scale: data.scale || '',
desc: data.desc ? data.desc.replace(/\t/, ' ').replace(/(^\s+| +$)/gm, '') : ''
},
+ xhrFields: {
+ withCredentials: true
+ },
crossDomain: true
})
.done(function (_data) {
@@ -143,7 +148,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) {
})
// XXX: Buggy contextMenus on Firefox < v49
-if (browser.chrome || (browser.firefox && browser.version >= 49)) {
+if (browserInfo.chrome || (browserInfo.firefox && browserInfo.version >= 49) || browserInfo.msedge) {
chrome.contextMenus.onClicked.addListener(onClickHandler)
chrome.contextMenus.create({
@@ -167,6 +172,7 @@ chrome.browserAction.onClicked.addListener(function (tab) {
}
chrome.tabs.sendMessage(tab.id, {action: 'insertMenu', tab: tab}, function () {
chrome && chrome.runtime && chrome.runtime.lastError &&
+ chrome.runtime.lastError.number !== -2147467259 &&
!chrome.runtime.lastError.message.match(/message port closed/) &&
window.confirm(chrome.i18n.getMessage('confirmReload')) &&
chrome.tabs.reload(tab.id)
@@ -1,3 +1,4 @@
+require('chrome-browser-object-polyfill')
(function () {
'use strict'
let selector = document.getElementById('selector')