None of these have worked for me. My copy just complains about the lack of jQuery, and my primary system tries to load before the entire DOM has been loaded. And its check code is activated on every page load on Comicvine, when it should only be activated on the 4050 pages (right?) Also, tampermonkey doesn't seem like it'll let me get away without requring jQuery... and needs to have the @run-at set at the least, and maybe also that waiit_dom function. Based on recent git activity, it seems like these external calls are moving towards a more traditional web API (right?), so I'm sending the data async, and using the callback from the async get to put up notifications boxes. The color of the glow around the mylar logo indicates whether the request was successful (green) or failure (red). Eventually I'll add in support for whatever the API becomes.
Hopefully this works for those of you who had problems with other scripts.
Code: Select all
// ==UserScript==
// @name ComicVine: Add to Mylar
// @namespace https://comicvine.gamespot.com/addtomylar/4050-
// @author losty, btx
// @match *://comicvine.gamespot.com/*/4050-*/
// @version 0.3.2
// @run-at document-idle
// @grant GM_log
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @description Rewrite of the original "Add to Mylar" script. Key features: only match the Volume 4050 pages, wait for the DOM to load before attempting to manipulate it, use Ajax req to submit. To use: please set wshost & wsport if you use different IP/ports.
// @require https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==
(function() {
var wshost="localhost";
var wsport="8090";
var volid = window.location.pathname.split('/')[2].split('-')[1];
var ustr = "http://" + wshost + ":" + wsport + "/addbyid?comicid=" + volid + "&calledby=True";
function waitDom(sel) {
if ($(sel).length == 0) {
window.setTimeout(function() { waitDom(sel); }, 500);
return;
}
$('a.wiki-title').before($('<img class="mylarload" src="http://' + wshost + ':' + wsport + '/images/mylarlogo.png" title="Add this volume to Mylar" style="">'));
$('img.mylarload').css({cursor: 'pointer'}).on('click', function(e) {
$(this).addClass('spinny').removeClass('lastgood').removeClass('lastbad');
GM_xmlhttpRequest({
method: 'GET',
url: ustr,
data: null,
onload: function(response) {
$('img.mylarload').removeClass('spinny').addClass('lastgood');
GM_log(response.responseText);
GM_notification("Successfully submitted this volume back to your Mylar server.", "Success", null, null);
},
onerror: function(e) {
$('img.mylarload').removeClass('spinny').addClass('lastbad');
GM_log(e);
GM_notification("Failed to submit this volume back to your Mylar server.", "Failure", null, null);
}
})
return false;
})
}
GM_addStyle('.spinny { animation: spinning-cog 1.3s infinite ease; }');
GM_addStyle('@keyframes spinning-cog { 0% { transform: rotate(0deg); } 20% { transform: rotate(-45deg); } 100% { transform: rotate(360deg); } }');
GM_addStyle('img.mylarload { width:38px;margin-right:-38px;position:relative;left:-50px;filter:drop-shadow(0px 0px 14px #c0c010); }');
GM_addStyle('img.mylarload.lastgood { filter: drop-shadow(0px 0px 14px #00f010); }');
GM_addStyle('img.mylarload.lastbad { filter: drop-shadow(0px 0px 14px #f01000); }');
waitDom('span.volume-issue-count');
})();