Skip to content

Commit

Permalink
Version up v0.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kura52 authored and kura52 committed Jul 4, 2018
1 parent 6af1170 commit ac6d5e5
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 44 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.19.1
0.19.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sushi-browser",
"version": "0.19.1",
"version": "0.19.2",
"description": "Sushi Browser",
"main": "./lib/main.js",
"author": "kura52",
Expand Down
251 changes: 251 additions & 0 deletions src/base32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
;(function(){

// This would be the place to edit if you want a different
// Base32 implementation

var alphabet = '0123456789abcdefghjkmnpqrtuvwxyz'
var alias = { o:0, i:1, l:1, s:5 }

/**
* Build a lookup table and memoize it
*
* Return an object that maps a character to its
* byte value.
*/

var lookup = function() {
var table = {}
// Invert 'alphabet'
for (var i = 0; i < alphabet.length; i++) {
table[alphabet[i]] = i
}
// Splice in 'alias'
for (var key in alias) {
if (!alias.hasOwnProperty(key)) continue
table[key] = table['' + alias[key]]
}
lookup = function() { return table }
return table
}

/**
* A streaming encoder
*
* var encoder = new base32.Encoder()
* var output1 = encoder.update(input1)
* var output2 = encoder.update(input2)
* var lastoutput = encode.update(lastinput, true)
*/

function Encoder() {
var skip = 0 // how many bits we will skip from the first byte
var bits = 0 // 5 high bits, carry from one byte to the next

this.output = ''

// Read one byte of input
// Should not really be used except by "update"
this.readByte = function(byte) {
// coerce the byte to an int
if (typeof byte == 'string') byte = byte.charCodeAt(0)

if (skip < 0) { // we have a carry from the previous byte
bits |= (byte >> (-skip))
} else { // no carry
bits = (byte << skip) & 248
}

if (skip > 3) {
// not enough data to produce a character, get us another one
skip -= 8
return 1
}

if (skip < 4) {
// produce a character
this.output += alphabet[bits >> 3]
skip += 5
}

return 0
}

// Flush any remaining bits left in the stream
this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}

/**
* Process additional input
*
* input: string of bytes to convert
* flush: boolean, should we flush any trailing bits left
* in the stream
* returns: a string of characters representing 'input' in base32
*/

Encoder.prototype.update = function(input, flush) {
for (var i = 0; i < input.length; ) {
i += this.readByte(input[i])
}
// consume all output
var output = this.output
this.output = ''
if (flush) {
output += this.finish()
}
return output
}

// Functions analogously to Encoder

function Decoder() {
var skip = 0 // how many bits we have from the previous character
var byte = 0 // current byte we're producing

this.output = ''

// Consume a character from the stream, store
// the output in this.output. As before, better
// to use update().
this.readChar = function(char) {
if (typeof char != 'string'){
if (typeof char == 'number') {
char = String.fromCharCode(char)
}
}
char = char.toLowerCase()
var val = lookup()[char]
if (typeof val == 'undefined') {
// character does not exist in our lookup table
return // skip silently. An alternative would be:
// throw Error('Could not find character "' + char + '" in lookup table.')
}
val <<= 3 // move to the high bits
byte |= val >>> skip
skip += 5
if (skip >= 8) {
// we have enough to preduce output
this.output += String.fromCharCode(byte)
skip -= 8
if (skip > 0) byte = (val << (5 - skip)) & 255
else byte = 0
}

}

this.finish = function(check) {
var output = this.output + (skip < 0 ? alphabet[bits >> 3] : '') + (check ? '$' : '')
this.output = ''
return output
}
}

Decoder.prototype.update = function(input, flush) {
for (var i = 0; i < input.length; i++) {
this.readChar(input[i])
}
var output = this.output
this.output = ''
if (flush) {
output += this.finish()
}
return output
}

/** Convenience functions
*
* These are the ones to use if you just have a string and
* want to convert it without dealing with streams and whatnot.
*/

// String of data goes in, Base32-encoded string comes out.
function encode(input) {
var encoder = new Encoder()
var output = encoder.update(input, true)
return output
}

// Base32-encoded string goes in, decoded data comes out.
function decode(input) {
var decoder = new Decoder()
var output = decoder.update(input, true)
return output
}

/**
* sha1 functions wrap the hash function from Node.js
*
* Several ways to use this:
*
* var hash = base32.sha1('Hello World')
* base32.sha1(process.stdin, function (err, data) {
* if (err) return console.log("Something went wrong: " + err.message)
* console.log("Your SHA1: " + data)
* }
* base32.sha1.file('/my/file/path', console.log)
*/

var crypto, fs
function sha1(input, cb) {
if (typeof crypto == 'undefined') crypto = require('crypto')
var hash = crypto.createHash('sha1')
hash.digest = (function(digest) {
return function() {
return encode(digest.call(this, 'binary'))
}
})(hash.digest)
if (cb) { // streaming
if (typeof input == 'string' || Buffer.isBuffer(input)) {
try {
return cb(null, sha1(input))
} catch (err) {
return cb(err, null)
}
}
if (!typeof input.on == 'function') return cb({ message: "Not a stream!" })
input.on('data', function(chunk) { hash.update(chunk) })
input.on('end', function() { cb(null, hash.digest()) })
return
}

// non-streaming
if (input) {
return hash.update(input).digest()
}
return hash
}
sha1.file = function(filename, cb) {
if (filename == '-') {
process.stdin.resume()
return sha1(process.stdin, cb)
}
if (typeof fs == 'undefined') fs = require('fs')
return fs.stat(filename, function(err, stats) {
if (err) return cb(err, null)
if (stats.isDirectory()) return cb({ dir: true, message: "Is a directory" })
return sha1(require('fs').createReadStream(filename), cb)
})
}

var base32 = {
Decoder: Decoder,
Encoder: Encoder,
encode: encode,
decode: decode,
sha1: sha1
}

if (typeof window !== 'undefined') {
// we're in a browser - OMG!
window.base32 = base32
}

if (typeof module !== 'undefined' && module.exports) {
// nodejs/browserify
module.exports = base32
}
})();
4 changes: 2 additions & 2 deletions src/chromeManifestModify.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export default async function modify(extensionId,verPath){
const manifestStr = removeBom(fs.readFileSync(manifestPath).toString()).replace('\\u003Call_urls>','<all_urls>')
const infos = hjson.parse(manifestStr)

if(!infos.key){
infos.key = extensionId
if(!infos.key || infos.key.match(/[\-\.]/)){
infos.key = extensionId.match(/^[\da-z]+$/) ? extensionId : require('./base32').encode(extensionId)
}

if(infos.permissions && infos.permissions.includes('activeTab')
Expand Down
16 changes: 5 additions & 11 deletions src/defaultExtension/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,14 @@ if(window.__started_){
}
else if(location.href.match(/^https:\/\/addons\.mozilla\.org\/.+?\/firefox/) && !document.querySelector('.Badge.Badge-not-compatible')){
let url
const func = _=>ipc.send('add-extension',{url})
setInterval(_=>{
const b = document.querySelector('.Button--confirm.Button--puffy')
const b = document.querySelector('.Button--action.Button--puffy:not(.Button--disabled)')
if(!b) return
b.classList.remove('Button--confirm')
b.classList.add('InstallButton-button')
b.classList.add('Button--action')
b.innerText = 'Add to Sushi'

const isDarwin = navigator.userAgent.includes('Mac OS X')
const isWin = navigator.userAgent.includes('Windows')
const files = Object.values(JSON.parse(document.querySelector('#redux-store-state').textContent).addons.byID)[0].platformFiles
const url = (files['all'] || files[isWin ? 'windows' : isDarwin ? 'mac' : 'linux']).url + 'dp-btn-primary'
if(b.href != 'javascript:void(0)') url = b.href

b.addEventListener('click',_=>ipc.send('add-extension',{url}))
b.innerText = 'Add to Sushi'
b.addEventListener('click',func)
b.href = 'javascript:void(0)'
},1000)
}
Expand Down
10 changes: 10 additions & 0 deletions src/render/TabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const convertUrlMap = new Map([
['chrome://settings#extensions','chrome-extension://dckpbojndfoinamcdamhkjhnjnmjkfjd/settings.html#extensions'],
])

const firefoxAddonSite = 'https://addons.mozilla.org'
const allSelectedkeys = sharedState.allSelectedkeys
const refs2 = {}

Expand Down Expand Up @@ -1356,6 +1357,15 @@ export default class TabPanel extends Component {
console.log('onLoadStart',e,Date.now() - ttime,Date.now())
if (!self.mounted || !e.isMainFrame) return

if(e.url.startsWith(firefoxAddonSite)){
const ua = navigator.userAgent.includes('Windows') ? 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0' :
navigator.userAgent.includes('Mac OS X') ? 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:61.0) Gecko/20100101 Firefox/61.0' :
'Mozilla/5.0 (X11; Linux i686; rv:61.0) Gecko/20100101 Firefox/61.0'
ipc.send('user-agent-change',{tabId:tab.wvId,ua,domain: firefoxAddonSite})
if(!tab.firefoxAddon) self.navigateTo(tab.page, e.url, tab)
tab.firefoxAddon = true
}

PubSub.publishSync(`on-load-start_${tab.key}`,e.url)
ipc.send('chrome-webNavigation-onBeforeNavigate',{
tabId:tab.wvId,
Expand Down
6 changes: 5 additions & 1 deletion src/userAgentChangeEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { ipcMain,session } from 'electron'

let first = true
const tabs = new Map()
ipcMain.on('user-agent-change', async (event, datas) => {
ipcMain.on('user-agent-change', async (event, datas, domain) => {
tabs.set(datas.tabId,datas.ua)
if(first){
const ret = session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
if(domain && !url.startsWith(domain)){
callback({})
return
}
const ua = tabs.get(details.tabId)
if(ua){
details.requestHeaders['User-Agent'] = ua
Expand Down
32 changes: 6 additions & 26 deletions tools/versionUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,14 @@ const glob = require("glob")
const BEFORE_CODE_NAME = 'Engawa(Flounder Fin)'
const CODE_NAME = 'Engawa(Flounder Fin)'
const CURRENT_APP_VERSION = fs.readFileSync('../VERSION.txt').toString()
const NEXT_APP_VERSION = "0.19.1"
const NEXT_APP_VERSION = "0.19.2"
const NEXT_APP_VERSION2 = `${NEXT_APP_VERSION.split(".").slice(0,-1).join('.')}${NEXT_APP_VERSION.split(".").slice(-1)[0]}`

const CHANGE_ENGLISH = `Added function to add selected text (HTML) to Note.
Added Note function to tool page.
Improved to be able to set the range for deleting data.
Added deletion function to history page.
Added function to display Tor process progress in the location bar.
Improved to restore active tab when session is restored.
Added option of Show Focus Location Bar of Top Page.
Updated to Muon 7.1.4.
Fixed bug that chrome extension setting disappears when changing file location.
Fixed display defect of multi panel function.
Fixed Tor tab's webrtc leak.
Fixed a lot of bugs.`

const CHANGE_JAPANESE = `選択したテキスト(HTML)をNoteへ追加する機能を追加
Note機能をツールページに追加
データを削除の設定に期間を設定できるよう改善
履歴ページに履歴の削除機能を追加
Torプロセスの進捗状況をロケーションバーに表示するよう改善
セッションの復帰時にアクティブタブを復元するよう改善
Show Focus Location Bar of Top Pageのオプションを追加
Muonを7.1.4に更新
ロケーションを変更するとchrome拡張の設定が消える不具合を修正
マルチパネル機能の表示不具合を修正
Torタブのwebrtc leakを修正
多数の不具合修正`
const CHANGE_ENGLISH = `Fixed WebExtension function bug.
Updated to youtube-dl 2018.07.04.`

const CHANGE_JAPANESE = `WebExtensionに対する処理のバグを修正
youtube-dlを2018.07.04に更新`

const isWindows = process.platform === 'win32'
const isDarwin = process.platform === 'darwin'
Expand Down
Loading

0 comments on commit ac6d5e5

Please sign in to comment.