Created
June 16, 2016 17:24
-
-
Save khsing/d8dedae2caf06c1182aef483a5b09f5e to your computer and use it in GitHub Desktop.
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 App Store Price History | |
// @namespace mybeky | |
// @author mybeky, khsing | |
// @include https://itunes.apple.com/* | |
// @description Add price history table in App Store page | |
// @icon http://cl.ly/FqTY/appshopper.png | |
// @version 0.1.2 | |
// @connect * | |
// @grant GM_xmlhttpRequest | |
// @grant GM_addStyle | |
// ==/UserScript== | |
(function () { | |
var title = document.title; | |
var app_name = document.getElementsByTagName('h1')[0].innerHTML; | |
app_name = app_name.replace(' — ', ' - ').split(' - ')[0]; | |
app_name = app_name.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); | |
app_name = app_name.replace(/"/g, "\"").replace(/'/g, "'").replace(/ /g, " "); | |
var platform = 'ios'; | |
if (title.indexOf('Mac App Store') === 0) { | |
platform = 'mac'; | |
} | |
var keywords = "intitle:\"" + app_name + "\" "; | |
keywords += "site:appshopper.com "; | |
keywords += "-site:appshopper.com/blog"; | |
var search_url = "https://www.google.com/search?filter=0&q=" + encodeURIComponent(keywords); | |
var app_id = location.href.match(/id(\d+)/)[1]; | |
var app_url; | |
var appshopper_urls; | |
//alert(search_url); | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: search_url, | |
onload: function(response) { | |
appshopper_urls = response.responseText.match(/http:\/\/appshopper.com\/[^"]*/g); | |
unsafeWindow.urls = appshopper_urls; | |
get_app_info(); | |
} | |
}); | |
function get_app_info() { | |
if (appshopper_urls.length === 0) { | |
return; | |
} | |
app_url = appshopper_urls.shift(); | |
if (platform == "mac" && app_url.indexOf('/mac/') == -1) { | |
get_app_info(); | |
} else { | |
//alert(app_url); | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: app_url, | |
onload: function(response) { | |
var responseHtml = response.responseText; | |
//alert(responseHtml); | |
unsafeWindow.h = responseHtml; | |
/* | |
var _app_id = responseHtml.match(/top200chart\.php\?id=(\d+)/)[1]; | |
if (_app_id != app_id) { | |
get_app_info(); | |
} else { | |
*/ | |
var price_table_html; | |
price_table_html = responseHtml.match(/<div class="items">[\s\S]*?(<ul class="activity">[\s\S]*?<\/ul>)/)[1]; | |
//alert(price_table_html); | |
//price_table_html = price_table_html.replace(/ (\d+) '\d+<\/th>/g, '.$1</th>'); | |
price_table_html = price_table_html.replace('New App: ', ''); | |
price_table_html = price_table_html.replace(/Version /g, 'v'); | |
//price_table_html = price_table_html.replace(/<td>.*? -> /g, '<td>'); | |
insert_table(price_table_html); | |
//} | |
} | |
}); | |
} | |
} | |
function insert_table(price_table_html) { | |
GM_addStyle('div#left-stack {width: 240px;}' + | |
'div#price-history {font-size: 90%; margin-bottom: 20px;color:#333;}' + | |
'div#price-history ul {width: 180px;}' + | |
//'div#price-history table th {font-family: monospace; font-size: 90%; width: 40px;}' + | |
'div#price-history ul li b {font-weight: bold;}' + | |
'div#price-history ul li span {font-size: 70%;}' + | |
'div#price-history ul li.updated {background: url("http://appshopper.com/images/style/type-update.png") no-repeat scroll right center transparent}' + | |
'div#price-history ul li.increase {background: url("http://appshopper.com/images/style/type-priceincrease.png") no-repeat scroll right center transparent}' + | |
'div#price-history ul li.decrease {background: url("http://appshopper.com/images/style/type-pricedrop.png") no-repeat scroll right center transparent}' + | |
'div#price-history ul li.new {background: url("http://appshopper.com/images/style/type-new.png") no-repeat scroll right center transparent }'); | |
var left_stack = document.getElementById('left-stack'); | |
var desc_list = left_stack.getElementsByTagName('ul')[0]; | |
var price_div = document.createElement('div'); | |
price_div.id = "price-history"; | |
price_div.innerHTML = price_table_html + '<a style="float:right; margin-right: 10px;" target="_blank" href="' + app_url + '">via AppShopper</a>'; | |
desc_list.parentNode.insertBefore(price_div, desc_list); | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment