Skip to content

Instantly share code, notes, and snippets.

@dashdanw
Created May 8, 2014 08:55
Show Gist options
  • Save dashdanw/26f941f303553cb2822d to your computer and use it in GitHub Desktop.
Save dashdanw/26f941f303553cb2822d to your computer and use it in GitHub Desktop.
Greasemonkey Script for FurAffinity (direct image links, auto-updates)
/****************************************************************************************
* FEATURES: *
* 1.In a gallery view press ctrl+alt+leftclick (windows,linux?) *
* or cmd+alt+leftclick (osx) to open the full sized image in a new tab *
* *
* 2.In a view page press ctrl+leftclick (windows, linux?) or *
* cmd+leftclick (osx) to open the image in a new tab, can also be *
* done by default by doing the same to "Download" *
* *
* 3.Automatically checks for new submissions, will dynamically change the *
* notification bar on the top every .5 seconds and color it light green if *
* there is a change (can be changed via settings) *
* *
* 4.Flags exist to enable(true)/disable(false) these 3 options below at *
* beginning of script script by setting "feat_1","feat_2", and "feat_3" *
* *
* TODO: *
* 1.To get the fullsize image names I currently rely on an xmlhttprequest *
* (SINCE FA NEVER OFFERS AN API! GAH!!!) which could be streamlined though *
* it is not too much overhead as the submission pages are a small amount of *
* code and it does not load resources on the page such as the images themselves *
* css, javascript etc. unless you load the image in which case you will have used *
* a lower net bandwidth having not had to load the resouces of the /view/ page *
* *
* 2.I'd like to add a way to one-click download the images themselves but I think *
* this may only be possible via HTML5 and i'm not sure you can force that via *
* GreaseMonkey... *
* 3.Feature one is sort of "hacked" *
****************************************************************************************/
// ==UserScript==
// @name furaffinity.net
// @namespace furaffinity-dash
// @description furaffinity.net addons
// @include furaffinity.net*
// @version 0.9
// @grant none
// // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
//user set variables:
var feat_1 = true;
var feat_2 = true;
var feat_3 = true;
/**************************************
* DO NOT CHANGE BEYOND THIS LINE! *
* (unless you know what you're doing) *
**************************************/
//global var for all methods
var addr = window.location.pathname;
//feature 2 (no jQuery)
var submission = document.getElementById('submissionImg');
if(submission && feat_2){
var sub_parent = submission.parentNode;
var sub_a = document.createElement('a');
sub_a.href = window.full_url;
sub_parent.appendChild(sub_a);
sub_a.appendChild(submission);
submission.onclick = function(e){
//when ctrl or cmd key is not depressed and you press the submission image do the normal action and don't redirect via the hyperlink
if(!(e.metaKey|| e.ctrlKey)){
this.src = window.xor_view();
return false;
}
}
}
//feature 1 (no jQuery)
document.getElementsByTagName('body')[0].onclick = function(e){
//when the user clicks a link and is holding shift+ctrl or shift+meta (osx compatability)
if((e.ctrlKey || e.metaKey) && e.altKey && feat_1){
var link = e.target.parentNode;
//if it's a hyperlink and it links to a view page grab the page and the image link inside of it
if(link.tagName.toLowerCase() == 'a' && link.href.indexOf("http://www.furaffinity.net/view/")==0){
//REQIEST PAGE PREVIEW
var look_ahead_req = new XMLHttpRequest();
look_ahead_req.open("GET", link.getAttribute('href'),false);
look_ahead_req.send();
var page_text = look_ahead_req.responseText;
var doc = document.implementation.createHTMLDocument('test');
doc.documentElement.innerHTML = look_ahead_req.responseText;
link.setAttribute('old_href',link.getAttribute('href'));
link.href = doc.getElementById("submissionImg").src;
link.setAttribute('new_href',link.getAttribute('href'));
link.onclick = function(e){
var parent = e.target.parentNode;
if(e.ctrlKey || e.metaKey){
parent.setAttribute('href',parent.getAttribute('new_href'));
}
else{
parent.setAttribute('href',parent.getAttribute('old_href'));
}
}
}
}
}
//feature 3 (uses jQuery)
//global vars for setInterval that don't need to be updated and need to be referenced in between function calls
var inbox_elem = jQuery('.noblock:first');
//parsing rgb(,,) css element to increment green color of update ba
var banner_rgb = jQuery('.header_bkg').css("background-color").split(", ");
var update_rgb = "rgb("+(banner_rgb[0].replace("rgb(",""))+", "+(parseInt(banner_rgb[1]) + 32)+", "+(banner_rgb[2].replace(")",""))+")";
banner_rgb = banner_rgb.join(",");
//check every 5 seconds for notification updates
if(feat_3){
setInterval(function(){
//REQUEST THE FRONTPAGE
var fp_req = new XMLHttpRequest();
fp_req.open("GET", "/",false);
fp_req.send();
//SPLIT UP INCOMING HTML TO GRAB THE UPDATES div
var new_inbox = fp_req.responseText.split('<li class="noblock">',2)[1].split("</li>",2)[0];
var old_inbox = inbox_elem.html();
//CHECK TO SEE IF THE INBOX HTML HAS CHANGED
if(new_inbox != old_inbox){
inbox_elem.html(new_inbox);
inbox_elem.css('background-color',update_rgb);
}
else {
inbox_elem.css('background-color',banner_rgb);
}
},5000);
}
@vulpesfoxnik
Copy link

downloadLink = doc.documentElement.querySelector('a[href^="//d.facdn.net/art/"]').href;

@dashdanw
Copy link
Author

ah yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment