Skip to content

Commit

Permalink
0813 修正中文網址的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
pulipulichen committed Aug 12, 2019
1 parent 6339453 commit 583ad9a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/helpers/URLHelper.js
Expand Up @@ -2,9 +2,9 @@ let URLHelper = {
_pattern: new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'), // fragment locator
'(\\:\\d+)?(\\/[-a-z\u4e00-\u9eff\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\u4e00-\u9eff\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\u4e00-\u9eff\\d_]*)?$', 'i'), // fragment locator
isURL: function (url) {
if (url.indexOf('#') > -1) {
url = url.slice(0, url.indexOf('#'))
Expand Down
Binary file added app/imgs/predefined-icons/google-contacts.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/libs/CrawlerIconURLManager.js
Expand Up @@ -94,6 +94,16 @@ let CrawlerIconURLManager = {
return result
}
},
{
match: function (url) {
return (url.startsWith("https://contacts.google.com/"))
},
process: function (url, $, callback) {
let result = `predefined-icons/google-contacts.png`
callback(result)
return result
}
},
],
match: function (url, $, callback) {
for (let i = 0; i < this.conf.length; i++) {
Expand Down
15 changes: 13 additions & 2 deletions app/libs/CrawlerManager.js
Expand Up @@ -21,7 +21,7 @@ let CrawlerManager = {
body = bodyStr
}
body = this._decodeHTML(body)
console.log(body)
//console.log(body)

let $ = cheerio.load(body)
data.title = this._parseTitle($, urlObject.host)
Expand All @@ -46,9 +46,18 @@ let CrawlerManager = {

},
_requestBody: function (url, callback) {

let encoding = null

if (url.startsWith('https://webatm.post.gov.tw/')) {
encoding = 'binary'
}
//url = encodeURI(url)
//console.log(url)
request({
url: url,
encoding: 'binary',
//encoding: 'binary',
encoding: encoding,
headers: { 'User-Agent': 'Mozilla/5.0' }
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
Expand Down Expand Up @@ -87,12 +96,14 @@ let CrawlerManager = {
return desc
},
_decodeHTML: function (body) {
//console.log(body)
if (body.indexOf('content="text/html; charset=big5"') > -1
|| (body.indexOf('CONTENT="text/html; charset=big5"') > -1)) {
//console.log(body)
//console.log(iconv.decode(body, 'Big5').toString())
//console.log(iconv.decode(body, 'UTF8').toString())
body = iconv.decode(body, 'BIG5').toString()
//console.log('decode')
}
//console.log(body)
return body.trim()
Expand Down
2 changes: 1 addition & 1 deletion app/require.js
Expand Up @@ -11,7 +11,7 @@ const homedir = require('os').homedir()

let ws = null // for module "windows-shortcut"
if (process.platform === 'win32') {
ws = require('windows-shortcuts')
ws = require('@pulipuli.chen/windows-shortcuts')
}
let exec = require('child_process').exec

Expand Down
18 changes: 17 additions & 1 deletion app/scripts.js
Expand Up @@ -16,7 +16,8 @@ let appConfig = {
isNeedLoad: false,
_enablePersist: true,
_debugDemo: false,
_debugConsole: false
_debugConsole: false,
_urlWatchLock: undefined
},
watch: {
url: function (newUrl) {
Expand All @@ -26,6 +27,19 @@ let appConfig = {
newUrl = newUrl.slice(newUrl.lastIndexOf(' --app=') + 7)
this.url = newUrl
}

//console.log(this._urlWatchLock)

if (this._urlWatchLock === undefined && encodeURI(newUrl) !== newUrl) {
this._urlWatchLock = true
setTimeout(() => {
this.url = encodeURI(newUrl)
setTimeout(() => {
this._urlWatchLock = undefined
}, 100)
}, 100)
}

//return 'http://blog.pulipuli.info'

},
Expand Down Expand Up @@ -255,6 +269,8 @@ let appConfig = {
desc: this.description
//icon: 'D:/Desktop/Box Sync/[SOFTWARE]/[SavedIcons]/[ico]/Apps-Google-Drive-Slides-icon.ico',
}

//console.log(options)
ShortcutManager.create(saveToPath, options)
},
onFileDrop: function (dropFiles) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"request": "^2.87.0",
"terminal-exec": "^0.0.2",
"universalify": "^0.1.2",
"windows-shortcuts": "^0.1.6"
"@pulipuli.chen/windows-shortcuts": "^0.1.6"
},
"devDependencies": {
"electron": "^6.0.1"
Expand Down

0 comments on commit 583ad9a

Please sign in to comment.