Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merge 0.3.7
  • Loading branch information
swdyh committed Sep 21, 2014
2 parents 72661ff + 039fa8f commit 7b65744
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.markdown
Expand Up @@ -12,3 +12,5 @@ AutoPagerize: <http://github.com/swdyh/autopagerize/tree/master>
Install Chrome Extension here.<br />
<http://autopagerize.net/>

Chrome Web Store
https://chrome.google.com/webstore/detail/autopagerize/igiofjhpmpihnifddepnpngfjhkfenbp
81 changes: 37 additions & 44 deletions src/autopagerize.user.js
Expand Up @@ -211,7 +211,7 @@ AutoPager.prototype.request = function() {
this.lastRequestURL = this.requestURL
this.showLoading(true)
if (Extension.isFirefox()) {
extension.postMessage('get', { url: this.requestURL, fromURL: location.href, charset: document.characterSet, cookie: document.cookie }, function(res) {
extension.postMessage('get', { url: this.requestURL, fromURL: location.href, charset: document.characterSet }, function(res) {
if (res.responseText && res.finalURL) {
self.load(createHTMLDocumentByString(res.responseText), res.finalURL)
}
Expand Down Expand Up @@ -248,10 +248,6 @@ AutoPager.prototype.load = function(htmlDoc, url) {
this.error()
return
}

AutoPager.documentFilters.forEach(function(i) {
i(htmlDoc, this.requestURL, this.info)
}, this)
try {
var page = getElementsByXPath(this.info.pageElement, htmlDoc)
var url = this.getNextURL(this.info.nextLink, htmlDoc, this.requestURL)
Expand Down Expand Up @@ -328,8 +324,13 @@ AutoPager.prototype.addPage = function(htmlDoc, page) {
this.insertPoint.parentNode.insertBefore(p, this.insertPoint)
}

p.innerHTML = 'page: <a class="autopagerize_link" href="' +
this.requestURL.replace(/&/g, '&amp;') + '">' + (++this.pageNum) + '</a>'
var aplink = document.createElement('a')
aplink.className = 'autopagerize_link'
aplink.href = this.requestURL
aplink.appendChild(document.createTextNode(String(++this.pageNum)))
p.appendChild(document.createTextNode('page: '))
p.appendChild(aplink)

return page.map(function(i) {
var pe = document.importNode(i, true)
self.insertPoint.parentNode.insertBefore(pe, self.insertPoint)
Expand Down Expand Up @@ -391,10 +392,7 @@ AutoPager.prototype.error = function() {
}, 3000)
}
}

AutoPager.documentFilters = []
AutoPager.filters = []

AutoPager.launchAutoPager = function(list) {
if (list.length == 0) {
return
Expand Down Expand Up @@ -429,38 +427,21 @@ AutoPager.launchAutoPager = function(list) {
}
}

if (window != window.parent) {
return
}

var linkFilter = function(doc, url) {
var base = getFirstElementByXPath('//base[@href]', doc)
var baseUrl = base ? base.href : url
var isSameBase = isSameBaseUrl(location.href, baseUrl)
if (!FORCE_TARGET_WINDOW && isSameBase) {
return
}

var anchors = getElementsByXPath('descendant-or-self::a[@href]', doc)
anchors.forEach(function(i) {
var attrHref = i.getAttribute('href')
if (FORCE_TARGET_WINDOW && !attrHref.match(/^#|^javascript:/) &&
i.className.indexOf('autopagerize_link') < 0) {
i.target = '_blank'
}
if (!isSameBase && !attrHref.match(/^#|^\w+:/)) {
i.href = resolvePath(i.getAttribute('href'), baseUrl)
// firefox about:addon(http://localhost/extensions-dummy/discoveryURL)
// Error: Permission denied to access property 'href'
if (Extension.isFirefox()) {
try {
if (window.location.href != window.parent.location.href) {
return
}
})

if (!isSameBase) {
var images = getElementsByXPath('descendant-or-self::img[@src]', doc)
images.forEach(function(i) {
i.src = resolvePath(i.getAttribute('src'), baseUrl)
})
}
catch(e) {
return
}
}
else if (window != window.parent) {
return
}
AutoPager.documentFilters.push(linkFilter)

if (Extension.isFirefox()) {
fixResolvePath()
Expand All @@ -471,9 +452,6 @@ if (typeof(window.AutoPagerize) == 'undefined') {
window.AutoPagerize.addFilter = function(f) {
AutoPager.filters.push(f)
}
window.AutoPagerize.addDocumentFilter = function(f) {
AutoPager.documentFilters.push(f)
}
window.AutoPagerize.launchAutoPager = AutoPager.launchAutoPager
var ev = document.createEvent('Event')
ev.initEvent('GM_AutoPagerizeLoaded', true, false)
Expand Down Expand Up @@ -507,7 +485,22 @@ if (location.href.match('^http://[^.]+\.google\.(?:[^.]{2,3}\.)?[^./]{2,3}/.*(&f
// console.log([location.href, to])
location.href = to
}

// fix youtube thumbnails
// http://www.youtube.com/results?search_query=a
if ((/^https?:\/\/www.youtube.com\/results.+/).test(location.href)) {
var youtubeSearchShowThumbnalFilter = function(nodes) {
nodes.forEach(function(i) {
Array.prototype.slice.call(
i.querySelectorAll('img[data-thumb]')
).forEach(function(i) {
if ((/\.gif$/).test(i.src) && i.dataset.thumb) {
i.src = i.dataset.thumb
}
})
})
}
AutoPager.filters.push(youtubeSearchShowThumbnalFilter)
}

// utility functions.
function getElementsByXPath(xpath, node) {
Expand Down Expand Up @@ -572,7 +565,7 @@ function addDefaultPrefix(xpath, prefix) {
}

function debug() {
if ( typeof DEBUG != 'undefined' && DEBUG ) {
if (typeof DEBUG != 'undefined' && DEBUG && console.log.apply) {
console.log.apply(console, arguments)
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/background.js
Expand Up @@ -41,11 +41,10 @@ function init() {
con.postMessage({ name: message.name, data: res })
}
else if (message.name == 'launched') {
port.onMessage.addListener(function(message, con) {
var tabid = con.sender.tab.id
var path = 'icons/icon16.png'
chrome.pageAction.show(tabid)
chrome.pageAction.setIcon({tabId:tabid, path: path})
var tabid = con.sender.tab.id
chrome.pageAction.show(tabid)
chrome.pageAction.setIcon({
tabId:tabid, path: 'icons/icon16.png'
})
}
else if (message.name == 'siteinfo_meta') {
Expand Down Expand Up @@ -84,7 +83,6 @@ function loadLocalSiteinfoCallback(data) {
if (cache[url_old]) {
delete cache[url_old]
localStorage['cacheInfo'] = JSON.stringify(cache)
console.log(Object.keys(cache))
}
refreshSiteinfo()
}
Expand Down Expand Up @@ -159,4 +157,3 @@ function get(url, callback, opt) {
xhr.send(null)
return xhr
}

4 changes: 2 additions & 2 deletions src/manifest.json
Expand Up @@ -24,8 +24,8 @@
"page": "background.html"
},
"options_page": "options.html",
"version": "0.3.6",
"icons": {
"version": "0.3.8",
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
Expand Down

0 comments on commit 7b65744

Please sign in to comment.