Skip to content

Commit f72a112

Browse files
authored
Use Jquery post instead of GM.xmlHttpRequest
1 parent 2fbef4e commit f72a112

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

ItchioSimpleRemoveFromCollection.user.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// ==UserScript==
22
// @name Itch.io Simple Remove from Collection
33
// @namespace https://github.com/refatK
4-
// @version 1.0.1
4+
// @version 1.0.2
55
// @homepageURL https://github.com/refatK/Itch.io-Simple-Remove-from-Collection
66
// @description Easily remove games from your itch.io collections from within the "Add to Collection" modal of a game.
77
// @author RefatK
88
// @license MIT
9-
// @updateURL https://github.com/refatK/Itch.io-Simple-Remove-from-Collection/raw/main/ItchioSimpleRemoveFromCollection.user.js
109
// @match *://itch.io/*
1110
// @match *://*.itch.io/*
1211
// @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
@@ -18,7 +17,7 @@
1817
// ==/UserScript==
1918

2019
/* jshint esversion: 8 */
21-
/* global $, Itch */
20+
/* global $, Itch, I */
2221
$(document).ready(function () {
2322
const GAME_URL_REGEX = "/https:\/\/.+\.itch\.io/g"
2423
const bodyObserver = new MutationObserver(OnBodyChange);
@@ -122,20 +121,23 @@ $(document).ready(function () {
122121
}
123122

124123
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
137128
},
138129
});
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+
})
139141
}
140142

141143
function AddAndEnableRemoveButtons() {

0 commit comments

Comments
 (0)