【发布时间】:2012-10-31 10:33:55
【问题描述】:
我想从https://play.google.com/store/account* 获取一个值,这使得用户页面通过其输出。例如:/store/account?start=0&num=40,然后是/store/account?start=40&num=40等
现在,当我访问 https://play.google.com/apps 时,我希望 Greasemonkey 将 /store/account 页面中的值累加起来,然后在该页面上显示最终值。
下面列出的代码可以汇总来自/store/account 页面的我想要的值。但是,我想将代码插入到用于第二个 URL 的脚本中,这样我就可以在同一页面上添加它。
// ==UserScript==
// @name Google Play
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
var startParam = location.search.match (/\bstart=(\d+)/i);
if (startParam) {
var totalPrice = 0;
var startNum = parseInt (startParam[1], 10);
if (startNum === 0) {
GM_setValue ("TotalPrice", "0");
}
else {
totalPrice = parseFloat (GM_getValue ("TotalPrice", 0) );
}
$("#tab-body-account .rap-link").each( function () {
var price = $(this).attr ("data-docprice").replace (/[^\d\.]/g, "");
if (price) {
price = parseFloat (price);
if (typeof price === "number") {
totalPrice += price;
}
}
} );
//console.log ("totalPrice: ", totalPrice.toFixed(2) );
$('.tabbed-panel-tab').before (
'<div id="SumTotal">*Combined Value: $'+ totalPrice.toFixed(2) +'</div>'
);
GM_setValue ("TotalPrice", "" + totalPrice);
if ( $(".snippet.snippet-tiny").length ) {
startNum += 40;
var nextPage = location.href.replace (
/\bstart=\d+/i, "start=" + startNum
);
location.assign (nextPage);
}
}
【问题讨论】:
标签: javascript jquery greasemonkey mashup