// DeviantFUNCTIONS user script
// version 0.4RC1
// 2008-04-14
// Copyright (c) 2008, Justin Eittreim
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://www.greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "DeviantFUNCTIONS", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name DeviantFUNCTIONS
// @namespace http://Kyogo.deviantart.com
// @description Privides a quick and easy list of common Deviant Functions while on a Deviants page.
// @include http://*.deviantart.com/*
// @exclude http://chat.deviantart.com/*
// @exclude http://deviantart.com/
// @exclude http://deviantart.com/*
// @exclude http://www.deviantart.com/
// @exclude http://www.deviantart.com/*
// @exclude http://my.deviantart.com/*
// @exclude http://services.deviantart.com/*
// @exclude http://shop.deviantart.com/*
// @exclude http://browse.deviantart.com/*
// @exclude http://news.deviantart.com/*
// @exclude http://today.deviantart.com/*
// @exclude http://forum.deviantart.com/*
// ==/UserScript==
//start the script with a one second delay.
setTimeout(function(e) {
//Main
with(unsafeWindow) {
//Get the url of the current page.
var url = window.location.href;
//Get rid of the http://.
var striphttp = url.split('//')[1];
//Get the username from the url.
var userfromurl = striphttp.split('.')[0];
//Form a new url, the Deviant's page.
var endurl = 'http://'+userfromurl+'.deviantart.com/';
//Store the source code of the current page to a variable.
var sourcecode = document.body.innerHTML;
//Array of themes
var themes = new Array();
//Secure variable
var ok = false;
//menu status variables.
var open_m = false;
var open_t = false;
var animating = false;
var cant = false;
themes['black_plastic'] = ''
+ '<style type="text/css">'
+ '#FuncMenu {overflow:hidden;background:transparent url(http://i286.photobucket.com/albums/ll91/Elligari/b_p-1.png) repeat-y}'
+ '#FuncMenu h2 {color:#333333;}'
+ '#FuncMenu h3 {color:#ffffff;}'
+ '#FuncMenu h2:hover, #FuncMenu h3:hover {color:#acadff}'
+ '#FuncMenu b {color:#ffffff;}'
+ '#FuncMenu b:hover {color:#acadff}'
+ '#FuncMenu i {color:#acadff;}'
+ '#FuncMenu i:hover {color:#fcbacf}'
+ '</style>';
themes['silver_slate'] = ''
+ '<style type="text/css">'
+ '#FuncMenu {overflow:hidden;background:transparent url(http://i286.photobucket.com/albums/ll91/Elligari/s_s.png) repeat-y}'
+ '#FuncMenu h2 {color:#333333;}'
+ '#FuncMenu h3 {color:#777777;}'
+ '#FuncMenu h2:hover, #FuncMenu h3:hover {color:#acadff}'
+ '#FuncMenu b {color:#777777;}'
+ '#FuncMenu b:hover {color:#acadff}'
+ '#FuncMenu i {color:#88bfb4;}'
+ '#FuncMenu i:hover {color:#fcbacf}'
+ '</style>';
themes['dA-minimal'] = ''
+ '<style type="text/css">'
+ '#FuncMenu {overflow:hidden;background:#374341;-moz-border-radius-bottomleft:50px;-moz-border-radius-bottomright:50px;border-left:#6A7872 3px solid;border-right:#6A7872 3px solid;border-bottom:#6A7872 3px solid;}'
+ '#FuncMenu h2 {color:#91A298;}'
+ '#FuncMenu h3 {color:#BAC5BA;}'
+ '#FuncMenu h2:hover, #FuncMenu h3:hover {color:#acadff}'
+ '#FuncMenu b {color:#FFFFFF;}'
+ '#FuncMenu b:hover {color:#acadff}'
+ '#FuncMenu i {color:#6A78A2;}'
+ '#FuncMenu i:hover {color:#fcbacf}'
+ '</style>';
//XMLHttpRequest
var f_h_n = new XMLHttpRequest();
//The url we check for daily deviations
var nURL = 'http://'+userfromurl+'.deviantart.com/';
//Read it
f_h_n.open("GET",nURL,false);
//Send a 'null' package
f_h_n.send(null)
//if we read the page correctly
if ( f_h_n.status == 200 ) {
//store the source
sourcecode = f_h_n.responseText;
//if we find a 'send note' link...
if (sourcecode.match(/http:\/\/my\.deviantart\.com\/notes\/\?tk=/)) {
//Get the note key.
var tok = sourcecode.split("http://my.deviantart.com/notes/?tk=");
//Make sure that's all we get
var tik = tok[1].split("\"");
//And put it to a variable
var tk = tik[0];
//Form a new url with it.
var notesend = '<a href="http://my.deviantart.com/notes/?tk='+tk+'&subject=Hello!"><i>Send Note</i></a><br />';
} else {
//Or if there is no note link, disable the 'Send Note' link.
var notesend = '<a>Send Note</a><br />';
}
}
//new XMLHttpRequest
var f_h = new XMLHttpRequest();
//The url we check for daily deviations
var sURL = 'http://'+userfromurl+'.deviantart.com/dds/';
//Read it
f_h.open("GET",sURL,false);
//Send a 'null' package
f_h.send(null)
//if we read the page correctly
if ( f_h.status == 200 ) {
//store the source
s_c = f_h.responseText;
//if we find a certain string of tags
if (s_c.match(/<div class="stream"><div class="tt-a" ><span class="tt-w"><span class="shadow">/)) {
//the user has daily deviations
var ddcheck = '<a href="http://'+userfromurl+'.deviantart.com/dds/"><i>Daily Deviations</i></a><br />';
//or
} else {
//Disable the link
var ddcheck = '<a>Daily Deviations</a><br />';
}
}
//Another XMLHttpRequest
var f_h_w = new XMLHttpRequest();
//The url we check for daily deviations
var wURL = 'http://'+userfromurl+'.deviantart.com/';
//Read it
f_h_w.open("GET",wURL,false);
//Send a 'null' package
f_h_w.send(null)
//if we read the page correctly
if ( f_h_w.status == 200 ) {
//store the source
s_c_w = f_h_w.responseText;
//if we find a certain tag
if (s_c_w.match(/Watch this deviant/)) {
//the user has daily deviations
var dwcheck = '<a href="http://my.deviantart.com/deviants/add/'+userfromurl+'"><i>Watch '+userfromurl+'</i></a><br />';
//or
} else {
//Disable the link
var dwcheck = '<a>Watch '+userfromurl+'</a><br />';
}
}
//Placement variables.
var t = document.getElementById('shoppingCartCounterContainer');
//New link element
var link = document.createElement('a');
//Catch click events
if (link.captureEvents) link.captureEvents(Event.CLICK);
//Change the cursor on hover
link.style.cursor = 'pointer';
//Name of the menu link.
link.innerHTML = 'DeviantFUNCTIONS';
//Spacer variables.
var spacer = document.createElement('span');
//Internals
spacer.appendChild(document.createTextNode(' | '));
//Set the ID
spacer.setAttribute("id","extendspacer");
//Define a new spacer as a variable
var spacer_t = document.createElement('span');
//Internals of the spacer
spacer_t.appendChild(document.createTextNode(' | '));
//Set the ID
spacer_t.setAttribute("id","extendspacer");
//Place the menu link.
t.parentNode.insertBefore(spacer,t);
//Again
t.parentNode.insertBefore(link,spacer.nextSibling);
//Themes link
var link_t = document.createElement('a');
//Capture events from clicks
if (link_t.captureEvents) link_t.captureEvents(Event.CLICK);
//Change the corsur when the user hovers over the link
link_t.style.cursor = 'pointer';
//Name of the menu link.
link_t.innerHTML = 'Change Theme';
//Themes window close link
var link_tc = document.createElement('a');
//Capture events from clicks
if (link_tc.captureEvents) link_t.captureEvents(Event.CLICK);
//Change the corsur when the user hovers over the link
link_tc.style.cursor = 'pointer';
//Name of the menu link.
link_tc.innerHTML = '<b>Close</b>';
//Create the inner div, the menu.
FuncMenu = document.createElement('div');
//Set the menus ID.
FuncMenu.id = "FuncMenu";
//Get theme from cookie
theme = getCookie('theme');
if ( theme != null && theme != "" ) {
getCookie('theme');
theme = themes[theme]
} else {
setCookie('theme','dA-minimal',365);
theme = themes['dA-minimal'];
}
//The content of the menu.
FuncMenu.innerHTML = '<h2>Menu</h2>'
+ theme
+ '<div>'
+ '<b>Visit Their...</b><br />'
+ '<a href="'+endurl+'"><i>Userpage</i></a><br />'
+ '<a href="'+endurl+'gallery"><i>Gallery</i></a><br />'
+ '<a href="'+endurl+'gallery/scraps/"><i>Scraps</i></a><br />'
+ ddcheck
+ '<a href="'+endurl+'prints/"><i>Prints</i></a><br />'
+ '<a href="'+endurl+'journal/"><i>Journal</i></a><br />'
+ '<a href="'+endurl+'favourites/"><i>Favourites</i></a><br />'
+ '<a href="'+endurl+'friends/"><i>Watchers</i></a><br />'
+ '<b>Actions</b><br />'
+ notesend
+ '<a href="'+endurl+'#commentbody"><i>Leave a Comment</i></a><br />'
+ dwcheck
+ '</div>';
//Invisible, for now.
FuncMenu.style.display = "none";
//Set the cursor when hovering over the menu.
FuncMenu.style.cursor = 'pointer';
//Default Font Color inside the menu.
FuncMenu.style.color = "#ffffff";
//Center it.
FuncMenu.style.textAlign = "center";
//The width of the menu overall.
FuncMenu.style.width = "200px";
//Set the height.
FuncMenu.style.height = "0px";
//Needed.
FuncMenu.style.padding = "3px";
//Move the menu more towards the link that activates it.
FuncMenu.style.marginLeft = "300px";
//Placing...
link.parentNode.insertBefore(FuncMenu,link_t.nextSibling);
//Theme Window
ThemeWindow = document.createElement('div');
//Set the windows ID.
ThemeWindow.id = "changeTheme";
//The content of the window.
ThemeWindow.innerHTML = '<h2>Themes</h2>'
+ '<style type="text/css">'
+ '#changeTheme {background:#90A197;color:#ffffff;border:#6A7872 3px solid;}'
+ '#changeTheme b {color:#000000;}'
+ '#changeTheme li {color:#70dbaf;}'
+ '#changeTheme li:hover {color:#db7038}'
+ '#changeTheme ul {font-family: sans-serif;font-size: small;font-variant: small-caps;font-weight: bold;list-style-type: disc;text-align: left;}'
+ '</style>'
+ '<div>'
+ '<b>Select a theme to use with DeviantFUNCTIONS</b><br />'
+ '<ul>'
+ '<li onclick=\'document.cookie="theme=dA-minimal;expires=Fri, 07 Aug 2011 13:33:37 GMT;domain=.deviantart.com;path=/;host=.deviantart.com";location.reload(true);\'>dA-Minimal</li>'
+ '<li onclick=\'document.cookie="theme=black_plastic;expires=Fri, 07 Aug 2011 13:33:37 GMT;domain=.deviantart.com;path=/;host=.deviantart.com";location.reload(true);\'>Black Plastic</li>'
+ '<li onclick=\'document.cookie="theme=silver_slate;expires=Fri, 07 Aug 2011 13:33:37 GMT;domain=.deviantart.com;path=/;host=.deviantart.com";location.reload(true);\'>Silver Slate</li>'
+ '</ul>'
+ '</div>';
//Invisible.
ThemeWindow.style.display = "none";
//Default Font Color.
ThemeWindow.style.color = "#ffffff";
//Center it.
ThemeWindow.style.textAlign = "center";
//The width.
ThemeWindow.style.width = "200px";
//The height.
ThemeWindow.style.height = "300px";
//Needed, again.
ThemeWindow.style.padding = "3px";
//Margin.
ThemeWindow.style.marginLeft = "50%";
//Place it.
FuncMenu.parentNode.insertBefore(ThemeWindow,FuncMenu.nextSibling);
//link
FuncMenu.appendChild(link_t);
//link, again
ThemeWindow.appendChild(link_tc);
//Function to display the menu.
function activate(name) {
object = document.getElementById(name);
if ( object.style.display != "block" ) {
object.style.display = "block";
}
if ( object.style.padding != "3px" ) {
object.style.padding = "3px";
}
dyn = object.offsetHeight;
din = object.style.height.replace("px", "");
if ( din < 425 ) {
object.style.height = dyn + 5 + 'px';
setTimeout(function(e) { activate("FuncMenu"); }, 0);
return object;
} else {
object.style.height = '425px';
ok = true;
return object;
}
}
//Function to close the menu.
function deactivate(name) {
ok = false;
object_de = document.getElementById(name);
dyn_de = object_de.offsetHeight;
din_de = object_de.style.height.replace("px", "");
if ( din_de > 0 ) {
object_de.style.height = dyn_de - 30 + 'px';
setTimeout(function(e) { deactivate("FuncMenu"); }, 0);
return object_de;
}
}
//Function to open the theme window.
function changeTheme() {
object_t = document.getElementById('changeTheme');
object_t.style.display = 'block';
return object_t;
}
//Set a cookies value
function setCookie(c_name,value,expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString() + ';domain=.deviantart.com;path=/;host=.deviantart.com');
}
//Or get it
function getCookie(c_name) {
if (document.cookie.length>0) {
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1) {
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
//Open the menu when the user clicks the link.
link.onclick = function(e) {
if ( cant ) {
return false;
} else {
if ( open_m ) {
if ( animating ) {
cant = true;
deactivate("FuncMenu");
setTimeout(function(e) { FuncMenu.style.padding = "0px"; }, 1000);
setTimeout(function(e) { FuncMenu.style.height = "0px"; }, 1000);
setTimeout(function(e) { cant = false; }, 1000);
return false;
} else {
cant = true;
animating = true;
deactivate("FuncMenu");
setTimeout(function(e) { FuncMenu.style.padding = "0px"; }, 1000);
setTimeout(function(e) { FuncMenu.style.height = "0px"; }, 1000);
setTimeout(function(e) { open_m = false; }, 2000);
setTimeout(function(e) { animating = false; }, 2000);
setTimeout(function(e) { cant = false; }, 2000);
}
} else {
if ( animating ) {
cant = true;
deactivate("FuncMenu");
setTimeout(function(e) { FuncMenu.style.padding = "0px"; }, 800);
setTimeout(function(e) { FuncMenu.style.height = "0px"; }, 800);
setTimeout(function(e) { cant = false; }, 800);
return false;
} else {
if ( ThemeWindow.style.display != "block" ) {
cant = true;
animating = true;
activate("FuncMenu");
setTimeout(function(e) { open_m = true; }, 2000);
setTimeout(function(e) { animating = false; }, 2000);
setTimeout(function(e) { cant = false; }, 2000);
} else {
cant = true;
animating = true;
ThemeWindow.style.display = "none";
activate("FuncMenu");
setTimeout(function(e) { open_m = true; }, 2000);
setTimeout(function(e) { animating = false; }, 2000);
setTimeout(function(e) { cant = false; }, 2000);
}
}
}
}
};
//Open the themes window.
link_t.onclick = function(e) {
if ( open_t ) {
setTimeout(function(e) { open_t = false; }, 150);
setTimeout(function(e) { ThemeWindow.style.display = "none"; }, 10);
} else {
if ( animating ) {
return false;
} else {
if ( FuncMenu.style.height != '0px' ) {
FuncMenu.style.display = "none";
setTimeout(function(e) { changeTheme(); }, 10);
setTimeout(function(e) { open_t = true; }, 100);
} else {
setTimeout(function(e) { changeTheme(); }, 10);
setTimeout(function(e) { open_t = true; }, 100);
}
}
}
};
//Close theme window, link
link_tc.onclick = function(e) {
setTimeout(function(e) { open_t = false; }, 150);
setTimeout(function(e) { ThemeWindow.style.display = "none"; }, 10);
}
//Close it when they click anything/anywhere in the menu.
FuncMenu.onclick = function(e) {
if ( ok ) {
if ( animating ) {
return false;
} else {
animating = true;
deactivate("FuncMenu");
setTimeout(function(e) { FuncMenu.style.padding = "0px"; }, 800);
setTimeout(function(e) { FuncMenu.style.height = "0px"; }, 800);
setTimeout(function(e) { animating = false; }, 1500);
}
}
};
//When the user clicks the ThemeWindow
ThemeWindow.onclick = function(e) {
if ( animating ) {
return false;
} else {
setTimeout(function(e) { ThemeWindow.style.display = "none"; }, 10);
setTimeout(function(e) { open_t = false; }, 100);
}
};
//Last minute procedures
if ( FuncMenu.style.height.replace("px", "") > 390 ) {
FuncMenu.style.height = '425px';
} else if( FuncMenu.style.height.replace("px", "") < 15 & FuncMenu.style.height.replace("px", "") > 1 ) {
FuncMenu.style.height = '0px';
}
//Finish off.
}
//End main
}, 100);
/*-----------------------------------_\
:- DeviantFUNCTIONS V0.4RC/
/////////////////////////*
/*EOF*/