// ==UserScript==
// @name dev_star_com
// @namespace dev_star_com
// @description keep an eye on selected comments!
// @include http://*.deviantart.com/*
// @version 1.38
// @grant GM_registerMenuCommand
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
// if(navigator.appName=="Opera"){
// var storage=window.opera.scriptStorage;
// if(storage){
// GM_setValue=function(Name, Wert) {
// storage.setItem(Name,Wert);
// };
// GM_getValue=function(Name) {
// return storage.getItem(Name);
// }
// }else{
// var hint = document.createElement('div');
// hint.setAttribute('style',"font:10pt Verdana,Arial,Helvetica,sans-serif!important;background-color:#FFF;left:"+ ((window.innerWidth - 600)/2 - 20) +"px;top:"+ ((window.innerHeight - 150)/2 - 20) +"px;width:600px;height:150px;padding:10px;border:1px double black;position:absolute;z-index:999;");
// hint.id="devhint";
// hint.innerHTML="If you want to use this script, you have to allow Script-Storage!<br />ScriptStorage is a way to save data within opera that is only available to the userscript that saved it<br />To enable it, please visit <a href='opera:config#PersistentStorage|UserJSStorageQuota'>here</a> and insert a bigger number than 0! (depends on how many comments you would like to save. a good value is about 5000)<br /><p style='text-align:center' ><a style='cursor:pointer;' onclick='document.body.removeChild(document.getElementById(\"devhint\"));'>Close</a></p>";
// document.body.appendChild(hint);
// }
// }
var favimg="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAYAAAArdgcFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRm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GZn5%2B%2FTa4iMjLybnR09GuU21Ztbe3Z5OTkJYwgL5hksVjkOcepqSlBwV5MTEwInFagTM%2Fw2LbII1eB%2FARAgREREen4sFNTU3MGYxngLYAIlMXvBF4FI%2F875JBHrpz3qxsggqPx8fFLGE%2FjEdfdEhiF2WwW5eXlR%2F8Ee5WSKjw8%2FCE2wgNMsSJFPz1ARuqBjo6OSm4JjAIn%2FYWUbqBSNPSXL%2FI%2Ff6qoqKgHISEhprq6ukNCuQHBY2NjMnRkZERCtBJzTFVXVx%2FSnn7XgS9ThJo1t7W1uTxADxQwGTw4OEgJqqmp6RQXOOATTDpScgsX%2Bxn17mKUFKEU6lkGDwwMUILC23DFx8d%2F8guu1Wqf44VaOzs7XYySam9vl3D8c7TbH7jsc2ws9fb2CgqPx5WWlmZFUM98tgLcujY3N9cG6GlXV5ek1%2BtPcGF2RLeOPm6G1gGyY7OTjo4OgT7zG12SbUDrC66Eox5P%2BBt6hxMnOEhMTNyMiYl5h0t7iWp4wZHzhISETWx6gJM40cS%2BI5V6Xz1eBQddXl6eIysry4aNjISxEfE58z44cs51AI0ZGRk22DrwTecr70rWKqQGIATjE%2FkZ%2F127Kq7zu9tO7a7x6%2F874ci3g4KC7qN13mOk1xyVKbxFO9rT72rO%2FwAJ2DoMsxrvMwAAAABJRU5ErkJggg%3D%3D";
var favmessid=new Array();
var favmessparam=new Array();
var topclick=false;
var onc=0;
init();
function resets(){
if(GM_getValue("dev_star_com_username_starid")){
favmessid=GM_getValue("dev_star_com_username_starid").split(String.fromCharCode(13));
for(var i in favmessid){
GM_deleteValue("star_"+favmessid[i]);
}
GM_deleteValue("dev_star_com_username_starid");
GM_deleteValue("dev_star_com_username_starpar");
favmessid="";
init();
}
}
function init(){
GM_registerMenuCommand("reset dev_star_com", resets,"r");
favbutinsert();
if(document.getElementsByClassName("page2")[0]){//Message-Center-Pages
var cont = document.getElementsByClassName("page2")[0];
var clickbut=document.createElement("a");
clickbut.className="f";
clickbut.id="def_star_com_menu";
clickbut.setAttribute("style","cursor: pointer;");
clickbut.innerHTML="<i class='icon i19'></i><span class='ttext'>Starred Comments</span>";
// var notelink=document.getElementsByClassName("page2")[0].getElementsByClassName("f");
// for(var lin in notelink){
// if(notelink[lin].getAttribute("mcuid")=="notes"){notelink=notelink[lin];break;}
// }
notelink=document.getElementsByClassName("messages-folder-zone")[0];
cont.insertBefore(clickbut,notelink.nextSibling);
clickbut.addEventListener('click',anzeige,false);
cont.addEventListener('click',raumer,false);
// var $=unsafeWindow.jQuery,holder,query,offset,fPage,pPage,lPage;
// $("#overhead .oh-l").click(raumer);
document.getElementById("overhead").addEventListener('click',function(){topclick=true;raumer();},false);
}
if(location.href.match(/.*#view=starrCom.*/)){anzeige();}
}
function favbutinsert(){
if(!(location.href.match(/.*?\.deviantart\.com(\/#\/.*)?/)||location.href.match(/.*?\.deviantart\.com\/art\/.*/)||location.href.match(/.*?\.deviantart\.com\/gallery\/.*/))){return;}
var arr=document.getElementsByClassName('cc-meta');
if(location.href.match(/.*?\.deviantart\.com(\/#\/.*)?/)&&onc==0){onc=1;setTimeout(favbutinsert,2000);return;}
if(arr[0]){ //page contains comments
if(GM_getValue("dev_star_com_username_starid")){favmessid=GM_getValue("dev_star_com_username_starid").split(String.fromCharCode(13));}
for(var i in arr){
if(arr[i].tagName=="DIV"){
var favbut = document.createElement("img");
favbut.className="dev_favbut";
var gmid=arr[i].parentNode.parentNode.parentNode.parentNode.getAttribute("gmi-commentid")
if(favmessid.indexOf(gmid)==-1){
favbut.src=notfavimg;
favbut.setAttribute("akt","1");
}else{
favbut.src=favimg;
favbut.setAttribute("akt","0");
}
favbut.setAttribute("style","position: absolute;right: 70px;");
arr[i].appendChild(favbut);
favbut.addEventListener('click',umschalt,false);
}
}
}else{
if(onc<10){
onc++;
setTimeout(favbutinsert,2000);
}
}
}
function raumer(){
var aktiv=document.getElementsByClassName("f selected");
if(typeof aktiv[0] == "undefined" || aktiv[0].id!="def_star_com_menu" || topclick){
topclick=false;
var inh=document.getElementsByClassName("mczone dev_star_com");
if(inh.length==0){return;}
inh[0].parentNode.removeChild(inh[0]);
}
}
function parget(obj){
var ausgabe=new Array();
var parname=new Array("gmi-splitid","gmi-private","gmi-typeid","gmi-itemid");
for(var i in parname){
ausgabe.push(obj.getAttribute(parname[i]));
}
return ausgabe.join(String.fromCharCode(12));
}
function parpush(obj,idd){
var parname=new Array("gmi-splitid","gmi-private","gmi-typeid","gmi-itemid");
for(var i in parname){
obj.setAttribute(parname[i],favmessparam[idd].split(String.fromCharCode(12))[i]);
}
}
function umschalt(){
if(this.getAttribute("akt")=="1"){
this.setAttribute("akt","0");
this.src=favimg;
if(GM_getValue("dev_star_com_username_starid")){favmessid=GM_getValue("dev_star_com_username_starid").split(String.fromCharCode(13));}
if(GM_getValue("dev_star_com_username_starpar")){favmessparam=GM_getValue("dev_star_com_username_starpar").split(String.fromCharCode(13));}
var gmi_id=this.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("gmi-commentid");
favmessid.push(gmi_id);
favmessparam.push(parget(this.parentNode.parentNode.parentNode.parentNode.parentNode));
GM_setValue("star_"+gmi_id,this.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML);
GM_setValue("dev_star_com_username_starid",favmessid.join(String.fromCharCode(13)))
GM_setValue("dev_star_com_username_starpar",favmessparam.join(String.fromCharCode(13)))
}else{
this.setAttribute("akt","1");this.src=notfavimg;
var gmi_id=this.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("gmi-commentid")
if(GM_getValue("dev_star_com_username_starid")){favmessid=GM_getValue("dev_star_com_username_starid").split(String.fromCharCode(13));}
if(GM_getValue("dev_star_com_username_starpar")){favmessparam=GM_getValue("dev_star_com_username_starpar").split(String.fromCharCode(13));}
favmessparam.splice(favmessid.indexOf(gmi_id),1);
favmessid.splice(favmessid.indexOf(gmi_id),1);
GM_setValue("star_"+gmi_id,"");
GM_setValue("dev_star_com_username_starid",favmessid.join(String.fromCharCode(13)))
GM_setValue("dev_star_com_username_starpar",favmessparam.join(String.fromCharCode(13)))
}
}
function anzeige(){
var offset=0;
var patt=/.*deviantart\.com\/notifications\/.*#view=starrCom.*-0*(\d+).*/;
if(location.href.match(patt)){offset=parseInt(location.href.match(patt)[1]);}
if(GM_getValue("dev_star_com_username_starid")){favmessid=GM_getValue("dev_star_com_username_starid").split(String.fromCharCode(13));}
if(GM_getValue("dev_star_com_username_starpar")){favmessparam=GM_getValue("dev_star_com_username_starpar").split(String.fromCharCode(13));}
var aktiv=document.getElementsByClassName("f selected");
if(aktiv[0]){aktiv[0].className="f";}
document.getElementById("def_star_com_menu").className="f selected";
var inh=document.getElementsByClassName("messages-right")[0];
inh.innerHTML="";
var divcont=document.createElement("div");
divcont.className="mczone dev_star_com";
divcont.innerHTML="<h2 class='mczone-title'>"+ favmessid.length + " starred Comments</h2>";
inh.appendChild(divcont);
for(var i=offset;i<favmessid.length&&i<(10+offset);i++){
var favbut = document.createElement("div");
favbut.className="ccomment ch";
favbut.setAttribute("gmi-commentid",favmessid[i]);
favbut.setAttribute("name","gmi-CComment");
favbut.setAttribute("data-gmiclass","CComment");
parpush(favbut,i);
favbut.innerHTML=GM_getValue("star_"+favmessid[i]);
divcont.appendChild(favbut);
var interfavimg=document.getElementsByClassName("dev_favbut");
interfavimg[interfavimg.length-1].addEventListener('click',umschalt,false);
}
var bbtext="<div class='pagination'><ul class='pages'><li class='prev'><a class='";
if(offset==0){bbtext+='disabled';}else{bbtext+='away';}
bbtext+="' id='dev_star_com_prev'>Previous</a></li><li class='next'><a class='";
if(offset+10>=favmessid.length){bbtext+='disabled';}else{bbtext+='away';}
bbtext+="' id='dev_star_com_next'>Next</a></li></ul></div>";
var navi=document.createElement("div");
navi.innerHTML=bbtext;
navi.className="pagination-wrapper";
divcont.appendChild(navi);
if(!location.href.match(/#view=starrCom/)){location.href=location.href.replace(/#.*/,"")+"#view=starrCom-0";}
if(offset!=0){
document.getElementById("dev_star_com_prev").addEventListener('click', function(){
location.href=location.href.replace(/#.*/,"")+"#view=starrCom-"+(offset-10);
anzeige();
});
}
if(offset+10<favmessid.length){
document.getElementById("dev_star_com_next").addEventListener('click', function(){
location.href=location.href.replace(/#.*/,"")+"#view=starrCom-"+(offset+10);
anzeige();
});
}
}