Advertisement
ilools

App Store Price History

Dec 16th, 2014
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. // ==UserScript==
  2. // @name App Store Price History
  3. // @namespace mybeky
  4. // @author mybeky
  5. // @include https://itunes.apple.com/*
  6. // @description Add price history table in App Store page
  7. // @icon http://cl.ly/FqTY/appshopper.png
  8. // @version 0.1.1
  9. // ==/UserScript==
  10.  
  11.  
  12. (function () {
  13. var title = document.title;
  14. var app_name = document.getElementsByTagName('h1')[0].innerHTML;
  15. app_name = app_name.split("\(");app_name = app_name[0];
  16. app_name = app_name.replace(' — ', ' - ').split(' - ')[0];
  17. app_name = app_name.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
  18. app_name = app_name.replace(/&quot;/g, "\"").replace(/&#039;/g, "'").replace(/&nbsp;/g, " ");
  19.  
  20. var platform = 'ios';
  21. if (title.indexOf('Mac App Store') == 0) {
  22. platform = 'mac';
  23. }
  24. var keywords = "intitle:\"" + app_name + "\" ";
  25. keywords += "site:appshopper.com ";
  26. keywords += "-site:appshopper.com/blog";
  27. var search_url = "https://www.google.com/search?filter=0&q=" + encodeURIComponent(keywords);
  28. var app_id = location.href.match(/id(\d+)/)[1];
  29. var app_url;
  30.  
  31. var appshopper_urls;
  32.  
  33. GM_xmlhttpRequest({
  34. method: "GET",
  35. url: search_url,
  36. onload: function(response) {
  37. appshopper_urls = response.responseText.match(/http:\/\/appshopper.com\/[^"]*/g);
  38. unsafeWindow.urls = appshopper_urls;
  39. get_app_info();
  40. }
  41. });
  42.  
  43. function get_app_info() {
  44. if (appshopper_urls.length == 0) {
  45. return;
  46. }
  47. app_url = appshopper_urls.shift();
  48. if (platform == "mac" && app_url.indexOf('/mac/') == -1) {
  49. get_app_info();
  50. } else {
  51. GM_xmlhttpRequest({
  52. method: "GET",
  53. url: app_url,
  54. onload: function(response) {
  55. var responseHtml = response.responseText;
  56. unsafeWindow.h = responseHtml;
  57. var _app_id = responseHtml.match(/top200chart\.php\?id=(\d+)/)[1];
  58. if (_app_id != app_id) {
  59. get_app_info();
  60. } else {
  61. var price_table_html;
  62. price_table_html = responseHtml.match(/<h3>App Activity<\/h3>[\s\S]*?(<table>[\s\S]*?<\/table>)/)[1];
  63. price_table_html = price_table_html.replace(/ (\d+) '\d+<\/th>/g, '.$1</th>');
  64. price_table_html = price_table_html.replace('New App: ', '');
  65. price_table_html = price_table_html.replace(/Version /g, 'v')
  66. price_table_html = price_table_html.replace(/<td>.*? -> /g, '<td>')
  67. insert_table(price_table_html);
  68. }
  69. }
  70. });
  71. }
  72. }
  73.  
  74. function insert_table(price_table_html) {
  75. GM_addStyle('div#left-stack {width: 240px;}' +
  76. 'div#price-history {font-size: 90%; margin-bottom: 20px;}' +
  77. 'div#price-history table {width: 180px;}' +
  78. 'div#price-history table th {font-family: monospace; font-size: 90%; width: 40px;}' +
  79. 'div#price-history table tr {font-weight: bold;}' +
  80. 'div#price-history table tr.update td {background: url("http://appshopper.com/images/style/type-update.png") no-repeat scroll right center transparent}' +
  81. 'div#price-history table tr.priceincrease td {background: url("http://appshopper.com/images/style/type-priceincrease.png") no-repeat scroll right center transparent}' +
  82. 'div#price-history table tr.pricedrop td {background: url("http://appshopper.com/images/style/type-pricedrop.png") no-repeat scroll right center transparent}' +
  83. 'div#price-history table tr.new td {background: url("http://appshopper.com/images/style/type-new.png") no-repeat scroll right center transparent}')
  84.  
  85. var left_stack = document.getElementById('left-stack');
  86. var desc_list = left_stack.getElementsByTagName('ul')[0];
  87.  
  88. var price_div = document.createElement('div');
  89. price_div.id = "price-history";
  90. price_div.innerHTML = price_table_html + '<a style="float:right; margin-right: 10px;" target="_blank" href="' + app_url + '">via AppShopper</a>';
  91. desc_list.parentNode.insertBefore(price_div, desc_list);
  92. }
  93. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement