ThumbCollectV2

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

目前為 2015-12-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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';
}