[Release] ComicVine Userscript

Information and Tutorials on features in Mylar and how to use it
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: [Release] ComicVine Userscript

Post by evilhero »

Just a quick update on this - since CV changed to https enforced now, this script won't work...so here's the updated one:

Code: Select all

// ==UserScript==
// @name        Comic Vine Mylar
// @namespace   https://comicvine.gamespot.com/
// @author      Losty
// @include     https://comicvine.gamespot.com/*
// @version     1
// ==/UserScript==
if ($($(".wiki-page-type")[0]).text().indexOf("Volume") != -1){
   current = $($(".instapaper_title")[0]).html();
   $($(".instapaper_title")[0]).html("<a href='http://localhost:8090/addbyid?comicid="+document.URL.split("/")[4].split("-")[1]+"' target='_blank'><img style='width:50px' alt='Download with Mylar' title='Download with Mylar' src='https://raw.githubusercontent.com/evilhero/mylar/master/data/images/mylarlogo.png'/></a>"+current);
}
kongponleu88
Posts: 1
Joined: Sat May 20, 2017 2:20 am

Re: [Release] ComicVine Userscript

Post by kongponleu88 »

nice
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: [Release] ComicVine Userscript

Post by evilhero »

Simple update to include the new CV url as it was pointing to an old one...
(remember to change the http://localhost:8090 from localhost to whatever it actually is, if it's different than localhost)

Code: Select all

// ==UserScript==
// @name           Comic Vine Mylar
// @namespace   https://comicvine.gamespot.com/
// @author          Losty
// @include         https://comicvine.gamespot.com/*
// @version         1
// @grant            none
// ==/UserScript==
if ($($(".wiki-page-type")[0]).text().indexOf("Volume") != -1){
   current = $($(".instapaper_title")[0]).html();
   $($(".instapaper_title")[0]).html("<a href='http://localhost:8090/addbyid?comicid="+document.URL.split("/")[4]+"&calledby=True' rel='nofollow' target='_blank'><img style='width:50px' alt='Add to your Watchlist' title='Add to your Watchlist' src='https://raw.githubusercontent.com/evilhero/mylar/master/data/images/mylarlogo.png'/></a>"+current);
}
User avatar
oldirtdog
Posts: 61
Joined: Fri Nov 04, 2016 7:52 pm

Re: [Release] ComicVine Userscript

Post by oldirtdog »

Maybe I'm missing something or perhaps it's related to the fact that I'm doing it on Safari, but the Tampermonkey console shows a parsing error: invalid token on the last line of the script. I just did a copy and paste of the last update from EvilHero.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: [Release] ComicVine Userscript

Post by evilhero »

Doh - copy/pasta error on my part. Forgot the trailing elipse "}" - modified the above code to include it so if you try again with the updated code it should work properly ;)
User avatar
oldirtdog
Posts: 61
Joined: Fri Nov 04, 2016 7:52 pm

Re: [Release] ComicVine Userscript

Post by oldirtdog »

Again, maybe I'm doing something wrong or maybe it's safari, but I'm just getting more errors in Tampermonkey... I'm using V.4.7.5826 if that matters... When I go to CV, I also don't see any mylar button on a comic page. Here's what I'm getting:

Line 9 warning shows $ is not defined, twice
Line 10 shows an error "Implicit global variable, assign as global property instead" and the warnings for current and $ not defined.
Line 11 shows the same $ warnings from line 9
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: [Release] ComicVine Userscript

Post by evilhero »

I"m limited in my troubleshooting abit on this, as I can only test on Chrome/IE.

However, the errors you listed are fine - mine has the same thing in them (due to $ being the declaration of a variable I believe), and it still works. The Mylar logo will only appear beside the series title when you're viewing the series page, not an issue page. (ie. https://comicvine.gamespot.com/volume/4050-22775/). Make sure you have the script enabled within the Tampermonkey dashboard. I'm using version 4.6 (having problems updating to 4.7 for some reason, but I don't think it would break things)

I've read about some problems with Tampermonkey and using Safari due to apple pulling back some support of some aspects that are required for Tampermonkey to work - but I honestly haven't a clue in regards to what's working vs. what's not when it comes to Mac stuff.
User avatar
oldirtdog
Posts: 61
Joined: Fri Nov 04, 2016 7:52 pm

Re: [Release] ComicVine Userscript

Post by oldirtdog »

ok, I see the button on the series... clicking it brings up a new, blank tab with my server name in the address... it seems like it works, and I can now see the series in mylar... I assume that's all it needs to do, so I think we're good to go... done in Safari, btw, so I guess it works there (for now) :)

Thank YOU!
bblatt
Posts: 1
Joined: Tue Mar 17, 2020 5:54 pm

Re: [Release] ComicVine Userscript

Post by bblatt »

I polished up the code

Code: Select all

// ==UserScript==
// @name        Comic Vine Mylar
// @namespace   http://comicvine.gamespot.com/
// @author      Losty
// @include     *comicvine.gamespot.com*
// @include     *www.comicvine.com*
// @namespace   http://www.comicvine.com/
// @version     1
// @grant none
// ==/UserScript==
// SET SERVER IP (NO http://)
var serverip = 'IP';
// SET SERVER PORT NUMBER
var serverport = 'PORT';
//DO NOT EDIT
if ($($(".wiki-page-type")[0]).text().indexOf("Volume") != -1){
   current = $($(".instapaper_title")[0]).html();
   $($(".instapaper_title")[0]).html("<a href='http://"+serverip+":"+serverport+"/addbyid?comicid="+document.URL.split("/")[4].split("-")[1]+"' target='_blank'><img style='width:50px' alt='Download with Mylar' title='Download with Mylar' src='https://raw.githubusercontent.com/evilhero/mylar/master/data/images/mylarlogo.png'/></a>"+current);
}
btx
Posts: 7
Joined: Mon Mar 02, 2020 12:28 am

Re: [Release] ComicVine Userscript

Post by btx »

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');
})();
Post Reply