Created
January 21, 2015 09:01
-
-
Save ethanliu/054b6a27f1bcb3c25d33 to your computer and use it in GitHub Desktop.
PChome auto pager script for greasemonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PChome Loader | |
// @namespace ETHAN_PCHOME | |
// @include http://*.pchome.com.tw/* | |
// @version 1.0.0 | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js | |
// @run-at document-end | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// ==/UserScript== | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
var viewportHeight = document.body.clientHeight; | |
$.ajaxSetup({ | |
'beforeSend' : function(xhr) { | |
xhr.overrideMimeType('text/html; charset=big5'); | |
}, | |
}); | |
$(window).scroll(function(){ | |
var offset = $(window).scrollTop(); | |
var $elem = $('.pgNumber').not('.loaded'); | |
var elementTop = $elem.offset().top - $elem.height(); | |
if (offset + viewportHeight >= elementTop) { | |
var link = $("a:contains('下一頁')", $elem).attr('href'); | |
$elem.addClass('loaded'); | |
if (link) { | |
// console.log(link); | |
$.get(link, function(response) { | |
// console.log(response); | |
// jQuery('#StoreBodyContainer table:nth-child(5)').nextAll() | |
var targetTable = $('#StoreBodyContainer', response); | |
var $content = $('table:nth-child(5)', targetTable).nextAll(); | |
$('table', $content).css('margin-top', '0px'); | |
$('table', $content).css('margin-bottom', '0px'); | |
// var pager = $('.pgNumber', response); | |
// content.append(pager); | |
$('.pgNumber:last').after($content); | |
}, 'html'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment