Skip to content

Instantly share code, notes, and snippets.

@ethanliu
Created January 21, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanliu/054b6a27f1bcb3c25d33 to your computer and use it in GitHub Desktop.
Save ethanliu/054b6a27f1bcb3c25d33 to your computer and use it in GitHub Desktop.
PChome auto pager script for greasemonkey
// ==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