|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Itch.io Simple Remove from Collection |
3 | 3 | // @namespace https://github.com/refatK |
4 | | -// @version 1.0.1 |
| 4 | +// @version 1.0.2 |
5 | 5 | // @homepageURL https://github.com/refatK/Itch.io-Simple-Remove-from-Collection |
6 | 6 | // @description Easily remove games from your itch.io collections from within the "Add to Collection" modal of a game. |
7 | 7 | // @author RefatK |
8 | 8 | // @license MIT |
9 | | -// @updateURL https://github.com/refatK/Itch.io-Simple-Remove-from-Collection/raw/main/ItchioSimpleRemoveFromCollection.user.js |
10 | 9 | // @match *://itch.io/* |
11 | 10 | // @match *://*.itch.io/* |
12 | 11 | // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js |
|
18 | 17 | // ==/UserScript== |
19 | 18 |
|
20 | 19 | /* jshint esversion: 8 */ |
21 | | -/* global $, Itch */ |
| 20 | +/* global $, Itch, I */ |
22 | 21 | $(document).ready(function () { |
23 | 22 | const GAME_URL_REGEX = "/https:\/\/.+\.itch\.io/g" |
24 | 23 | const bodyObserver = new MutationObserver(OnBodyChange); |
@@ -122,20 +121,23 @@ $(document).ready(function () { |
122 | 121 | } |
123 | 122 |
|
124 | 123 | function PostRemoveGameFromCollection(collectionId, gameId, csrf_token, elToHideOnSuccess) { |
125 | | - GM.xmlHttpRequest({ |
126 | | - method: "POST", |
127 | | - headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
128 | | - url: `https://itch.io/collection/${collectionId}/remove/${gameId}`, |
129 | | - data: `csrf_token=${csrf_token}`, |
130 | | - onload: function (res) { |
131 | | - let resJson = JSON.parse(res.responseText) |
132 | | - if (resJson.removed) { |
133 | | - elToHideOnSuccess.remove() |
134 | | - } else { |
135 | | - console.error(res.responseText) |
136 | | - } |
| 124 | + $.ajaxSetup({ |
| 125 | + crossDomain: true, |
| 126 | + xhrFields: { |
| 127 | + withCredentials: true |
137 | 128 | }, |
138 | 129 | }); |
| 130 | + $.post(`https://itch.io/collection/${collectionId}/remove/${gameId}`, I.with_csrf()) |
| 131 | + .done(function(res) { |
| 132 | + elToHideOnSuccess.remove() |
| 133 | + }) |
| 134 | + .fail(function(res) { |
| 135 | + alert("Failed to remove from collection. Check browser console for details.") |
| 136 | + console.log(res) |
| 137 | + }) |
| 138 | + .always(function(res) { |
| 139 | + ; |
| 140 | + }) |
139 | 141 | } |
140 | 142 |
|
141 | 143 | function AddAndEnableRemoveButtons() { |
|
0 commit comments