DeviantArt: Show artist names under thumbnails

Show the artist's name under thumbnails on the browse and search pages

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        DeviantArt: Show artist names under thumbnails
// @namespace   deviantart_show_artist
// @description Show the artist's name under thumbnails on the browse and search pages
// @include     http://www.deviantart.com/
// @include     http://www.deviantart.com/?*
// @include     http://browse.deviantart.com/*
// @include     http://www.deviantart.com/browse/*
// @include     https://www.deviantart.com/
// @include     https://www.deviantart.com/?*
// @include     https://browse.deviantart.com/*
// @include     https://www.deviantart.com/browse/*
// @version     1.1
// @grant       GM_Log
// ==/UserScript==

// This work is licensed under the Creative Commons Attribution 2.0 Generic License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/.

function hasClass(ele,cls) {
  if ((typeof(ele) == 'undefined') || (ele == null)) {
    return false;
  }
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function doShowArtist(target) {
    var thumbs = target.querySelectorAll(".tt-a.tt-fh")

    for(var i = 0; i < thumbs.length; i++) {
        thumb_username = thumbs[i].getAttribute("username")
        if (!hasClass(thumbs[i], "da_show_artist__expanded")) {
            cat_span = thumbs[i].querySelector(".category")
            un_span = document.createElement("SPAN")
            artist_link = document.createElement("A")
            artist_link.href = "http://" + thumb_username.toLowerCase() + ".deviantart.com/"
            artist_link.appendChild(document.createTextNode(thumb_username))
            un_span.appendChild(document.createTextNode("by "))
            un_span.appendChild(artist_link)
            cat_span.parentNode.insertBefore(un_span, cat_span)
        }
        thumbs[i].className = thumbs[i].className + " da_show_artist__expanded"
    }
}

function handleInsertion( event ) {
    if ((event.target.tagName == 'DIV') && (hasClass(event.target, "browse-results-page"))) {
        doShowArtist(event.target)
    }
}

doShowArtist(document)

document.body.addEventListener('DOMNodeInserted', handleInsertion, false)