ThumbCollectV2

This script allows you to quickly collect thumb-codes on deviantart, and grab usernames

当前为 2015-12-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ThumbCollectV2
// @namespace    http://kamal-q.deviantart.com/
// @version      0.2
// @description	 This script allows you to quickly collect thumb-codes on deviantart, and grab usernames
// @author       Kamal-Q
// @match        http://*.deviantart.com/*
// @match        https://*.deviantart.com/*
// @exclude	 	  http://*.sta.sh/*
// @exclude	 	  http://*.deviantart.com/
// @exclude	 	  http://shop.deviantart.com/*
// @exclude	 	  http://chat.deviantart.com/*
// @exclude	 	  http://*.deviantart.com/messages/*
// @exclude	 	  http://*.deviantart.com/notifications/*
// @exclude	 	  http://*.deviantart.com/journal/*
// @exclude	 	  http://*.deviantart.com/art/*
// @exclude	 	  http://*.deviantart.com/watch/*
// @exclude	 	  http://*.deviantart.com/submit/*
// @grant        none
// ==/UserScript==
thumbcollectInit();
function thumbcollectInit() {
  //-----------Create styling 
  var thStyle = document.createElement('style');
  //------modify styling attach to head ------ 
  thStyle.innerHTML = '.thumbButtonSelected{display:inline-block; width: 60px; height: 25px; margin: 1px 1px; border-radius: 3px; border: 0px; background-color:#414846;color:#D4DFD0;}';
  thStyle.innerHTML += '.thumbCollectButton{display:inline-block; width: 60px; height: 25px; margin: 1px 1px; border-radius: 3px; border: 0px; background-color:#475C4D;color:#ADC0B3;}';
  thStyle.innerHTML += '.thumbCollectButton:hover{background-color:#3D4F42;color:#D4DFD0;}';
  thStyle.innerHTML += '.thumbCollectDiv{position:relative;float: right; padding: 0px; font-size:90%;padding:0px 10px;}';
  thStyle.innerHTML += '.thumbCollectCode{display:inline-block;font-size:90%;color:#aa2211; margin-bottom:3px; float:left;}';
  thStyle.innerHTML += '.thumbCollectCode:hover{color:#ff5555;}';
  thStyle.innerHTML += '.thumbCollectSelected{font-size:90%;color:#509905; margin-bottom:3px; float:left;}';
  thStyle.innerHTML += '.thumbCollectSelected:hover{color:#11cc11;}';
  thStyle.innerHTML += '.thumbTaContainer{display:none;width:95%; height: 150px; position: absolute; box-shadow: 0px 0px 20px rgba(0,0,0,.5); background-color:#414846; border-radius:5px;}';
  thStyle.innerHTML += '.thumbTextarea{display:block;width:80%; margin:auto; height:105px; margin-top:5px;background-color:#D4DFD0; resize:none;text-align:center; border-radius:5px; border:0px;}';
  thStyle.innerHTML += '.thumbCloseButton{display:block;width:20%;height: 25px; margin:6px 6px; border: 0px; background-color: #dd3333;border-radius:5px;color:#CcDdCc; font-weight: bold;}';
  thStyle.innerHTML += '.thumbCloseButton:hover{background-color: #ff3333;border-radius: 5px;color:#ffffff;font-weight: bold;}';
  document.head.appendChild(thStyle);
  //Check if user is on a general, forum, or journal page
  var forumPage = window.location.href.indexOf('forum');
  var thumbsClassname = document.getElementsByClassName('thumb');
  //arrays to store thumbs and usernames
  var allThumbs = [];
  var selectedThumbs = [];
  var allUsers = [];
  var selectedUsers = [];
  var topnav = document.getElementsByClassName('oh-gap') [0]; //where buttons are attached on page
  //---------Create elements ----------
  var thDiv = document.createElement('div'); //holds textarea, button, and counter display
  var thContainer = document.createElement('textarea'); //holds array values/thumbcodes
  thContainer.readOnly = true;
  var thClose = document.createElement('button'); //used to hide the div
  var btAll = document.createElement('button'); //button for the all  
  var btSelected = document.createElement('button'); //button for selected
  var btUsers = document.createElement('button'); //button for users
  var btUSelected = document.createElement('button'); //button for selected users
  var btLabel = document.createElement('div'); //div to hold both buttons
  //-----------Modify buttons and apply styling --------
  btLabel.innerHTML = 'TC: ';
  btAll.innerHTML = 'Thumbs';
  btSelected.innerHTML = 'Picked';
  btUsers.innerHTML = 'Users';
  btUSelected.innerHTML = 'Picked';
  thClose.innerHTML = 'X';
  btUsers.className = 'thumbCollectButton';
  btAll.className = 'thumbCollectButton';
  btSelected.className = 'thumbCollectButton';
  btUSelected.className = 'thumbCollectButton';
  btLabel.className = 'thumbCollectDiv';
  thDiv.className = 'thumbTaContainer';
  thContainer.className = 'thumbTextarea';
  thClose.className = 'thumbCloseButton';
  //-----adding things to the page----------------------------
  thDiv.appendChild(thContainer);
  thDiv.appendChild(thClose);
  btLabel.appendChild(btAll);
  btLabel.appendChild(btSelected);
  btLabel.appendChild(btUsers);
  btLabel.appendChild(btUSelected);
  btLabel.appendChild(thDiv);
  topnav.appendChild(btLabel);
  //iterate over thumb links, add thumbcodes below images, create Thumb objects array
  for (var i = 0; i < thumbsClassname.length; i++) {
    var tCodeDiv = document.createElement('div');
    tCodeDiv.className = 'thumbCollectCode';
    var link = thumbsClassname[i].href;
    var endName = link.indexOf('.');
    var username = link.substring(7, endName);
    var endThumbcode = link.indexOf('?');
    var thumbcode;
    if (endThumbcode < 0) {
      thumbcode = ':thumb' + link.substring(link.length - 9) + ':';
    } else {
      thumbcode = ':thumb' + link.substring((endThumbcode - 9), endThumbcode) + ':';
    }
    thumbcode = thumbcode.replace('-', '');
    allThumbs[i] = thumbcode;
    //if user not in the array of users on page
    if (allUsers.indexOf(username) < 0) {
      allUsers.push(username);
    }
    tCodeDiv.username = username;
    tCodeDiv.thumbcode = thumbcode;
    tCodeDiv.innerHTML = thumbcode + ' ' + username;
    tCodeDiv.addEventListener('click', function () {
      closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected,btUSelected);
      if (this.className == 'thumbCollectCode') {
        this.className = 'thumbCollectSelected';
        selectedThumbs.push(this.thumbcode);
        selectedUsers.push(this.username);
      } else {
        this.className = 'thumbCollectCode';
        selectedThumbs.splice(selectedThumbs.indexOf(this.thumbcode),1);
        selectedUsers.splice(selectedUsers.indexOf(this.username),1);
      }      
    }, false); //add listener
    // determine where to add the thumbcode
    if (forumPage === - 1) {
      thumbsClassname[i].parentElement.parentElement.parentElement.appendChild(tCodeDiv);
    } else if (forumPage > - 1) {
      thumbsClassname[i].parentElement.parentElement.appendChild(tCodeDiv);
    }
  }
  //----adding listeners to buttons in nav-------------------
  btAll.addEventListener('click', function () {
    closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected);
    this.className = 'thumbButtonSelected';
    getSelection(thContainer, thDiv, btAll, btUsers, btSelected, allThumbs);
  }, false);
  btSelected.addEventListener('click', function () {
    closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected);
    this.className = 'thumbButtonSelected';
    getSelection(thContainer, thDiv, btAll, btUsers, btSelected, selectedThumbs);
  }, false);
  btUsers.addEventListener('click', function () {
    closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected);
    this.className = 'thumbButtonSelected';
    getSelection(thContainer, thDiv, btAll, btUsers, btSelected, allUsers);
  }, false);
  btUSelected.addEventListener('click', function () {
    closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected);
    this.className = 'thumbButtonSelected';
    getSelection(thContainer, thDiv, btAll, btUsers, btSelected, selectedUsers);
  }, false);
  thClose.addEventListener('click', function () {
    closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected);
  }, false);
}
//-----displays selected thumbcodes ----------------------------
function getSelection(thContainer, thDiv, btAll, btUsers, btSelected, selection) {
  thContainer.innerHTML = '';  
  if(selection.length>0){
   for (var i = 0; i < selection.length; i++) {
     thContainer.innerHTML += selection[i] + '\n';
   }
  }else{
    thContainer.innerHTML = ":'(";
  }
  thDiv.style.display = 'block';
  thContainer.select();
}
//-----closes thumbcodes display----------------------------
function closeThumbs(thContainer, thDiv, btAll, btUsers, btSelected, btUSelected) {
  thContainer.innerHTML = '';
  thDiv.style.display = 'none';
  btAll.className = 'thumbCollectButton';
  btUsers.className = 'thumbCollectButton';
  btSelected.className = 'thumbCollectButton';
  btUSelected.className = 'thumbCollectButton';
}