IMDB - produce directory name

produces a directory name ready to copy/paste

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        IMDB - produce directory name
// @namespace   KG
// @include     /^https?://www\.imdb\.com/title/tt\d{7}/($|\?)/
// @run-at	document-start
// @grant	none
// @version     0.9
// @description produces a directory name ready to copy/paste
// ==/UserScript==

if (!window.frameElement) {
	run();
}

function run() {
        var url = window.location + "";
	url = url.split("?")[0] + "fullcredits";
        
        var x = new XMLHttpRequest();
        x.open("GET",url);
        x.onload = function() { 
        	process(this.responseXML);
        }
        x.responseType = "document";
        x.send();
}

function process(response) {
        var directors = "";
        var titleYear = document.title.replace(" - IMDb", "");
        titleYear = titleYear.replace("(TV Series ", "(");
        titleYear = titleYear.replace("(TV mini-series ", "(");
        titleYear = titleYear.replace("(TV ", "(");
	titleYear = titleYear.replace(" (V)", "");
	titleYear = titleYear.replace(" (TV)", "");
	titleYear = titleYear.replace("/I)", ")");
	titleYear = titleYear.replace("/II)", ")");
	titleYear = titleYear.replace("/III)", ")");
        
        var headings = response.querySelectorAll('h4.dataHeaderWithBorder');
	for (i=0; i < headings.length; i++) {
		if (headings[i].textContent.indexOf('Directed by') != -1) {
			var dirLinks = headings[i].nextElementSibling.getElementsByTagName('a');
			break;
		}
	}
	
	if (dirLinks) {
		var sep = (dirLinks.length == 2) ? " & " : ", "; // choose seperator
        	for (i=0; i < dirLinks.length; i++) { 
        		directors += dirLinks[i].textContent.trim();
        		directors += (i < dirLinks.length-1) ? sep : "";
        	}
	}
	
	var resultBox = document.createElement('div');
	resultBox.innerHTML = "<textarea readonly id='resultBox' style='font-size:90%; background: #000; color: #fff; position: fixed; left: 0; bottom: 0; z-index: 999; resize: none;' rows='1' cols='50' onclick='javascript: this.select();'>"
		+ titleYear + ", " + directors + "</textarea>";
	document.body.appendChild(resultBox);
	document.getElementById("resultBox").select();
}