IsThereAnyDeal.com Collection Importer

Adds buttons to various sites to export your game lists to ITAD

当前为 2015-11-14 提交的版本,查看 最新版本

  1. // Generated by CoffeeScript 1.8.0
  2.  
  3. /* IsThereAnyDeal.com Collection Importer
  4.  
  5. Any patches to this script should be made against the original
  6. CoffeeScript source file available (and documented) at:
  7.  
  8. https://github.com/ssokolow/itad_importer
  9.  
  10. Copyright ©2014-2015 Stephan Sokolow
  11. License: MIT (http://opensource.org/licenses/MIT)
  12.  
  13. TODO:
  14. - Add a `@downloadURL` for the script
  15.  
  16. Note: While we do not use GM_info, we must request it to force the userscript
  17. to be isolated from the page so its jQuery doesn't collide with the site's
  18. jQuery.
  19.  
  20. // ==UserScript==
  21. // @name IsThereAnyDeal.com Collection Importer
  22. // @version 0.1b11
  23. // @namespace http://isthereanydeal.com/
  24. // @description Adds buttons to various sites to export your game lists to ITAD
  25. // @icon http://s3-eu-west-1.amazonaws.com/itad/images/banners/50x50.gif
  26. // @license MIT
  27. // @supportURL https://github.com/ssokolow/itad_importer/issues
  28. // @grant GM_info
  29. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
  30. //
  31. // @match *://www.dotemu.com/*
  32. // @match *://fireflowergames.com/my-lists/*
  33. // @match *://www.flyingbundle.com/users/account
  34. // @match *://www.gog.com/account*
  35. // @match *://www.gog.com/order/status/*
  36. // @match *://groupees.com/purchases
  37. // @match *://groupees.com/users/*
  38. // @match *://www.humblebundle.com/home*
  39. // @match *://www.humblebundle.com/downloads?key=*
  40. // @match *://www.humblebundle.com/s?key=*
  41. // @match *://indiegamestand.com/wallet.php
  42. // @match *://indiegamestand.com/wishlist.php
  43. // @match *://www.shinyloot.com/m/games*
  44. // @match *://www.shinyloot.com/m/wishlist*
  45. // ==/UserScript==
  46. */
  47. var BUTTON_LABEL, ITAD_12X12, ITAD_14X14_GRAY, attr, dotemu_add_button, gog_prepare_title, humble_make_button, humble_parse, scrapeGames, scrapers, shinyloot_insert_button, titlecase_cb, underscore_re, word_re;
  48.  
  49. BUTTON_LABEL = "Export to ITAD";
  50.  
  51. ITAD_12X12 = "data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAAZlBMVEUEbrIEbrIJcbQLcrQefboo\ng70rhb4thr8vh78zicA6jcNCksVLl8hWnctZn8xdoc1ipM9ipc9kptB5stZ6staCt9mHutqJu9ud\nxuGozeSrz+W72OrA2+zJ4O7U5vLX6PPn8fj3+vyC0mvkAAAAAXRSTlMAQObYZgAAAFdJREFUCB0F\nwYkCgUAABcA3CpElRyRH6/9/0kwCQALtZSwNglN9Pt5LR+jqGuelEaYbeBXh04P7KMwDeF6E8l1h\nW1vh8PsO/bWeiGPdl/kzdYjdBkACQP5LygQ7CM8T6wAAAABJRU5ErkJggg==";
  52.  
  53. ITAD_14X14_GRAY = "data:image/png;base64,\niVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAdVBMVEUEbrKTlaCTlZ+TlZ+UlqCY\nmaSYmqWcnqednqieoKmfoaugoqulprCvsLivsbiwsrmztLuztby2uL7BwsjDxcrExcvIyc7V1trW\n1trX2Nvn5+rp6evx8vP19fb39/j4+Pn5+fr7+/v7+/z8/Pz8/P39/f3///8J+FboAAAAJHRSTlMA\ny+rw8PHx8fHx8vLy9PT09PT19vf39/n5+fz8/f3+/v7+/v695LIzAAAAcUlEQVQIHQXBhwGCQAAE\nsHui2FHsBeyy/4gmSQGgJKWCeTNFVQJNN9yH2xJB+z3WZuf3kjDuD+B8I6wfIzAbpsLuCrg3QtsD\n9TAXJq8tOHYEl9+W0eHbEPaf06u/PvoWsXmuTNrdegwp1QJAVZICQMkf1qQG7Yh+Z60AAAAASUVO\nRK5CYII=";
  54.  
  55. underscore_re = /_/g;
  56.  
  57. word_re = /\b\w+/g;
  58.  
  59. titlecase_cb = function(s) {
  60. return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();
  61. };
  62.  
  63. attr = function(node, name) {
  64. return node.getAttribute(name);
  65. };
  66.  
  67. dotemu_add_button = function(parent_selector) {
  68. return $('<button></button>').html(BUTTON_LABEL).css({
  69. float: 'right',
  70. marginRight: '5px'
  71. }).appendTo(parent_selector);
  72. };
  73.  
  74. gog_prepare_title = function(elem) {
  75. var dom;
  76. dom = $('.product-title', elem).clone();
  77. $('._product-flag', dom).remove();
  78. return dom.text();
  79. };
  80.  
  81. humble_make_button = function() {
  82. var a, button, label;
  83. label = $('<span class="label"></span>').html(BUTTON_LABEL);
  84. a = $('<a class="a" href="#"></span>').html(BUTTON_LABEL).css('padding-left', '9px');
  85. return button = $('<div class="flexbtn active noicon"></div>').append('<div class="right"></div>').append(label).append(a);
  86. };
  87.  
  88. humble_parse = function() {
  89. var x, _i, _len, _ref, _results;
  90. _ref = $('div.row').has(' .downloads.windows .download, .downloads.linux .download, .downloads.mac .download, .downloads.android .download').find('div.title');
  91. _results = [];
  92. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  93. x = _ref[_i];
  94. _results.push({
  95. title: x.textContent.trim(),
  96. sources: ['humblestore']
  97. });
  98. }
  99. return _results;
  100. };
  101.  
  102. shinyloot_insert_button = function() {
  103. return $('<button></button>').html(BUTTON_LABEL).css({
  104. background: 'url("/images/filters/sort-background-inactive.png") ' + 'repeat-x scroll 0% 0% transparent',
  105. border: '1px solid #666',
  106. borderRadius: '2px',
  107. boxShadow: '0px 1px 6px #777',
  108. color: '#222',
  109. fontSize: '12px',
  110. fontWeight: 'bold',
  111. fontFamily: 'Arial,Helvetica,Sans-serif',
  112. float: 'right',
  113. padding: '2px 8px',
  114. marginRight: '-6px',
  115. verticalAlign: 'middle'
  116. }).appendTo('#content .header');
  117. };
  118.  
  119. scrapers = {
  120. 'www.dotemu.com': {
  121. 'https://www\\.dotemu\\.com/(en|fr|es)/user/?': [
  122. {
  123. 'source_id': 'dotemu',
  124. 'game_list': function() {
  125. var x, _i, _len, _ref, _results;
  126. _ref = $('div.my-games div.field-title a');
  127. _results = [];
  128. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  129. x = _ref[_i];
  130. _results.push({
  131. title: attr(x, 'title'),
  132. url: x.href,
  133. sources: ['dotemu']
  134. });
  135. }
  136. return _results;
  137. },
  138. 'insert_button': function() {
  139. return dotemu_add_button('div.my-games h2.pane-title');
  140. }
  141. }, {
  142. 'source_id': 'dotemu',
  143. 'game_list': function() {
  144. var x, _i, _len, _ref, _results;
  145. _ref = $('div.user-wishlist .views-field-title-1 a');
  146. _results = [];
  147. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  148. x = _ref[_i];
  149. _results.push({
  150. title: attr(x, 'title'),
  151. url: x.href,
  152. sources: ['dotemu']
  153. });
  154. }
  155. return _results;
  156. },
  157. 'insert_button': function() {
  158. return dotemu_add_button('.user-wishlist h2.pane-title');
  159. },
  160. 'is_wishlist': true
  161. }
  162. ]
  163. },
  164. 'fireflowergames.com': {
  165. '^http://fireflowergames\\.com/my-lists/(edit-my|view-a)-list/\\?.+': {
  166. 'source_id': 'fireflower',
  167. 'game_list': function() {
  168. var results, x, _i, _len, _results;
  169. results = $('table.wl-table tbody td.check-column input:checked').parents('tr').find('td.product-name a');
  170. if (!results.length) {
  171. results = $('table.wl-table td.product-name a');
  172. }
  173. _results = [];
  174. for (_i = 0, _len = results.length; _i < _len; _i++) {
  175. x = results[_i];
  176. _results.push({
  177. title: $(x).text().trim(),
  178. url: x.href,
  179. sources: ['fireflower']
  180. });
  181. }
  182. return _results;
  183. },
  184. 'insert_button': function() {
  185. return $('<a class="button"></a>').html(BUTTON_LABEL).wrap('<td></td>').appendTo($('table.wl-actions-table tbody:first').find('tr:last'));
  186. },
  187. 'is_wishlist': true
  188. }
  189. },
  190. 'www.flyingbundle.com': {
  191. 'https?://www\\.flyingbundle\\.com/users/account': {
  192. 'source_id': 'flying_bundle',
  193. 'game_list': function() {
  194. var x, _i, _len, _ref, _results;
  195. _ref = $(".div_btn_download[href^='/users/sources']").parents('li').find(':first');
  196. _results = [];
  197. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  198. x = _ref[_i];
  199. _results.push({
  200. title: $(x).text(),
  201. sources: 'flying_bundle'
  202. });
  203. }
  204. return _results;
  205. },
  206. 'insert_button': function() {
  207. var li;
  208. li = $("<li></li>").appendTo('.legenda_points ul');
  209. return $('<a href="#">' + BUTTON_LABEL + ' <img src="' + ITAD_14X14_GRAY + '" /></a>').css('text-transform', 'uppercase').wrap("<li></li>").appendTo(li);
  210. }
  211. }
  212. },
  213. 'www.gog.com': {
  214. '^https://www\\.gog\\.com/order/status/.+': {
  215. 'source_id': 'gog',
  216. 'game_list': function() {
  217. var x, _i, _len, _ref, _results;
  218. console.debug("game_list called for GOG order status page");
  219. _ref = $('.order__hero-unit ul.summary-list li');
  220. _results = [];
  221. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  222. x = _ref[_i];
  223. _results.push({
  224. title: $(x).text().trim(),
  225. sources: ['gog']
  226. });
  227. }
  228. return _results;
  229. },
  230. 'insert_button': function() {
  231. console.debug("insert_button called for GOG order status page");
  232. return $("<a class='_dropdown__item ng-scope'></a>").html("On ITAD").prependTo($('.order-message__actions ._dropdown__items').filter(':first'));
  233. }
  234. },
  235. '^https?://www\\.gog\\.com/account(/games(/(shelf|list))?)?/?(\\?|$)': {
  236. 'source_id': 'gog',
  237. 'game_list': function() {
  238. var x, _i, _len, _ref, _results;
  239. console.debug("game_list called for GOG collection page");
  240. _ref = $('.product-row');
  241. _results = [];
  242. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  243. x = _ref[_i];
  244. _results.push({
  245. id: attr(x, 'gog-product'),
  246. title: gog_prepare_title(x),
  247. sources: ['gog']
  248. });
  249. }
  250. return _results;
  251. },
  252. 'insert_button': function() {
  253. console.debug("insert_button called for GOG collection page");
  254. return $("<span></span>").css({
  255. float: 'right',
  256. cursor: 'pointer',
  257. position: 'relative',
  258. marginBottom: '-2em',
  259. zIndex: 1
  260. }).html(BUTTON_LABEL + " (This Page)").prependTo($('.collection-header').filter(':first'));
  261. }
  262. }
  263. },
  264. 'groupees.com': {
  265. 'https?://(www\\.)?groupees\\.com/(purchases|users/\\d+)': {
  266. 'source_id': 'other',
  267. 'game_list': function() {
  268. var x, _i, _len, _ref, _results;
  269. _ref = $('.product ul.dropdown-menu').parents('.details').find('h3');
  270. _results = [];
  271. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  272. x = _ref[_i];
  273. _results.push({
  274. title: x.textContent.trim(),
  275. sources: ['other']
  276. });
  277. }
  278. return _results;
  279. },
  280. 'insert_button': function() {
  281. return $("<button></button>").css({
  282. float: 'right'
  283. }).addClass('button btn btn-sm btn-primary').html(BUTTON_LABEL + " (Selected Bundle)").insertBefore("input[name='search']");
  284. }
  285. }
  286. },
  287. 'www.humblebundle.com': {
  288. 'https://www\\.humblebundle\\.com/home/library/?': {
  289. 'source_id': 'humblestore',
  290. 'game_list': function() {
  291. var x, _i, _len, _ref, _results;
  292. _ref = $('.subproduct-selector h2');
  293. _results = [];
  294. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  295. x = _ref[_i];
  296. _results.push({
  297. title: x.textContent.trim(),
  298. sources: ['humblestore']
  299. });
  300. }
  301. return _results;
  302. },
  303. 'insert_button': function() {
  304. var button, config, found_early, observer;
  305. config = {
  306. childList: true,
  307. subtree: true
  308. };
  309. button = $('<button class="download-button"></button>').html(BUTTON_LABEL).css({
  310. display: 'inline',
  311. border: '1px solid #CCC',
  312. background: '#F1F3F6',
  313. padding: '5px 10px 5px 10px',
  314. marginLeft: '10px'
  315. });
  316. found_early = $(".top-controls");
  317. if (found_early.length > 0) {
  318. console.log("Inserting button immediately.");
  319. button.appendTo(found_early);
  320. } else {
  321. console.log("Using MutationObserver for deferred button insertion.");
  322. observer = new MutationObserver(function(mutations) {
  323. return mutations.forEach(function(mutation) {
  324. var found, tnode_cls;
  325. tnode_cls = mutation.target.getAttribute("class");
  326. found = $(".top-controls", mutation.target);
  327. if (found.length > 0) {
  328. observer.disconnect();
  329. return button.appendTo(found);
  330. }
  331. });
  332. });
  333. observer.observe(document.querySelector('.js-library-holder'), config);
  334. }
  335. return button;
  336. }
  337. },
  338. 'https://www\\.humblebundle\\.com/home/?': {
  339. 'source_id': 'humblestore',
  340. 'game_list': humble_parse,
  341. 'insert_button': function() {
  342. return humble_make_button().css({
  343. float: 'right',
  344. fontSize: '14px',
  345. fontWeight: 'normal'
  346. }).prependTo('.base-main-wrapper h1');
  347. }
  348. },
  349. 'https://www\\.humblebundle\\.com/(download)?s\\?key=.+': {
  350. 'source_id': 'humblestore',
  351. 'game_list': humble_parse,
  352. 'insert_button': function() {
  353. var parent;
  354. parent = $('.js-gamelist-holder').parents('.whitebox');
  355. parent.find('.staple.s4').remove();
  356. return humble_make_button().css({
  357. position: 'absolute',
  358. top: 11,
  359. right: 17
  360. }).appendTo(parent);
  361. }
  362. }
  363. },
  364. 'indiegamestand.com': {
  365. 'https://indiegamestand\\.com/wallet\\.php': {
  366. 'source_id': 'indiegamestand',
  367. 'game_list': function() {
  368. var x, _i, _len, _ref, _ref1, _ref2, _ref3, _results;
  369. _ref = $('#wallet_contents .line-item');
  370. _results = [];
  371. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  372. x = _ref[_i];
  373. _results.push({
  374. url: (_ref1 = $('.game-thumb', x)) != null ? (_ref2 = _ref1.closest('a')) != null ? (_ref3 = _ref2[0]) != null ? _ref3.href : void 0 : void 0 : void 0,
  375. title: $('.game-title', x).text().trim(),
  376. sources: ['indiegamestand']
  377. });
  378. }
  379. return _results;
  380. },
  381. 'insert_button': function() {
  382. return $('<div class="request key"></div>').html(BUTTON_LABEL).wrapInner("<div></div>").css({
  383. display: 'inline-block',
  384. marginLeft: '1em',
  385. verticalAlign: 'middle'
  386. }).appendTo('#game_wallet h2');
  387. }
  388. },
  389. 'https://indiegamestand\\.com/wishlist\\.php': {
  390. 'source_id': 'indiegamestand',
  391. 'game_list': function() {
  392. var x, _i, _len, _ref, _ref1, _ref2, _ref3, _results;
  393. _ref = $('#store_browse_game_list .game_list_item');
  394. _results = [];
  395. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  396. x = _ref[_i];
  397. _results.push({
  398. url: (_ref1 = $('.game-thumb', x)) != null ? (_ref2 = _ref1.closest('a')) != null ? (_ref3 = _ref2[0]) != null ? _ref3.href : void 0 : void 0 : void 0,
  399. title: $('.game_details h3', x).text().trim(),
  400. sources: ['indiegamestand']
  401. });
  402. }
  403. return _results;
  404. },
  405. 'is_wishlist': true,
  406. 'insert_button': function() {
  407. var innerDiv;
  408. innerDiv = $("<div></div>").css({
  409. paddingLeft: '10px',
  410. background: 'url("images/icon-arrow.png") no-repeat scroll ' + '155px 45% transparent'
  411. });
  412. return $('<div class="request key"></div>').html(BUTTON_LABEL).wrapInner(innerDiv).css({
  413. display: 'inline-block',
  414. verticalAlign: 'middle',
  415. float: 'right',
  416. width: '170px',
  417. height: '21px',
  418. background: 'url("images/btn-bg-blue-longer.png") ' + 'no-repeat scroll 0px 0px transparent',
  419. lineHeight: '21px',
  420. color: '#FFF',
  421. whiteSpace: 'nowrap',
  422. marginLeft: '1em',
  423. marginBottom: '4px',
  424. fontSize: '12px',
  425. cursor: 'pointer'
  426. }).css({
  427. margin: '11px 5px auto auto'
  428. }).appendTo('#store_browse_game_list .header');
  429. }
  430. }
  431. },
  432. 'www.shinyloot.com': {
  433. 'https?://www\\.shinyloot\\.com/m/games/?': {
  434. 'source_id': 'shinyloot',
  435. 'game_list': function() {
  436. var x, _i, _len, _ref, _results;
  437. _ref = $('#accordion .ui-widget-content');
  438. _results = [];
  439. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  440. x = _ref[_i];
  441. _results.push({
  442. url: $('.right-float a img', x).closest('a')[0].href,
  443. title: $(x).prev('h3').text().trim(),
  444. sources: ['shinyloot']
  445. });
  446. }
  447. return _results;
  448. },
  449. 'insert_button': shinyloot_insert_button
  450. },
  451. 'https?://www\\.shinyloot\\.com/m/wishlist/?': {
  452. 'source_id': 'shinyloot',
  453. 'game_list': function() {
  454. var x, _i, _len, _ref, _results;
  455. _ref = $('.gameItem');
  456. _results = [];
  457. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  458. x = _ref[_i];
  459. _results.push({
  460. url: $('.gameInfo + a', x)[0].href,
  461. title: $('.gameName', x).text().trim()
  462. });
  463. }
  464. return _results;
  465. },
  466. 'insert_button': shinyloot_insert_button,
  467. 'is_wishlist': true
  468. }
  469. }
  470. };
  471.  
  472. scrapeGames = function(scraper_obj) {
  473. var form, params, url;
  474. params = {
  475. json: JSON.stringify(scraper_obj.game_list()),
  476. source: scraper_obj.source_id
  477. };
  478. url = scraper_obj.is_wishlist != null ? 'https://isthereanydeal.com/outside/user/wait/3rdparty' : 'https://isthereanydeal.com/outside/user/collection/3rdparty';
  479. form = $("<form id='itad_submitter' method='POST' />").attr('action', url);
  480. params['returnTo'] = location.href;
  481. form.css({
  482. display: 'none'
  483. });
  484. $.each(params, function(key, value) {
  485. return $("<input type='hidden' />").attr("name", key).attr("value", value).appendTo(form);
  486. });
  487. $(document.body).append(form);
  488. return form.submit();
  489. };
  490.  
  491. $(function() {
  492. var e, profile, profile_matched, regex, scraper, _fn, _i, _len, _ref, _results;
  493. console.log("Loading ITAD importer...");
  494. if (scrapers[location.host]) {
  495. console.log("Matched domain: " + location.host);
  496. _ref = scrapers[location.host];
  497. _results = [];
  498. for (regex in _ref) {
  499. profile = _ref[regex];
  500. try {
  501. profile_matched = location.href.match(regex);
  502. } catch (_error) {
  503. e = _error;
  504. console.error("Bad regex: " + regex);
  505. }
  506. if (profile_matched) {
  507. console.log("Matched profile: " + regex);
  508. $('.itad_btn, #itad_dlg, .itad_close').remove();
  509. if (!Array.isArray(profile)) {
  510. profile = [profile];
  511. }
  512. _fn = function(scraper) {
  513. console.log("Inserting ITAD button for source ID: " + scraper.source_id);
  514. return typeof scraper.insert_button === "function" ? scraper.insert_button().addClass('itad_btn').click(function() {
  515. console.log("ITAD button clicked");
  516. return scrapeGames(scraper);
  517. }) : void 0;
  518. };
  519. for (_i = 0, _len = profile.length; _i < _len; _i++) {
  520. scraper = profile[_i];
  521. _fn(scraper);
  522. }
  523. break;
  524. } else {
  525. _results.push(void 0);
  526. }
  527. }
  528. return _results;
  529. }
  530. });