PotPlayer forum breadcrumbs

Add breadcrumbs on PotPlayer's forum

当前为 2017-07-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        PotPlayer forum breadcrumbs
// @namespace   V@no
// @description Add breadcrumbs on PotPlayer's forum
// @include     https://potplayer.daum.net/forum/*
// @version     1.4
// @grant       none
// ==/UserScript==

var inToolbar = true; //show it at top toolbar? (true or false)


var bc = document.getElementsByClassName("btn-breadcrumb"),
		style = document.createElement("style"),
		css;


function _$(id)
{
	return document.getElementById(id);
}

function log(t)
{
	console.log(t);
}

function cs(id, data)
{
	let r = null;
	if (typeof(data) == "undefined")
	{
		r = cs.cookies(id);
		try
		{
			r = JSON.parse(r);
		}catch(e){}
	}
	else
	{
		try
		{
			r = cs.cookies(id, JSON.stringify(data));
		}
		catch(e){}
	}
	return r;
}
//https://gist.github.com/bronson/6707533
cs.cookies = function(name, value, ms)
{
	if(arguments.length < 2)
	{
		// read cookie
		let cookies = document.cookie.split(';');
		for(let i=0; i < cookies.length; i++)
		{
			let c = cookies[i].replace(/^\s+/, '');
			if(c.indexOf(name + '=') == 0)
			{
				return decodeURIComponent(c.substring(name.length+1).split('+').join(' '));
			}
		}
		return null;
	}

	// write cookie
	let date = new Date();
	if (typeof(ms) == "undefined")
		ms = 864000000000;

	date.setTime(date.getTime() + ms);
	document.cookie = name + "=" + encodeURIComponent(value) + (ms ? ";expires=" + date.toGMTString() : '') + ";path=/";
	return true;
}
var _inToolbar = cs("breadCrumbs");


if (_inToolbar !== null)
	inToolbar = _inToolbar;

inToolbar = (inToolbar && bc.length && _$("search")) ? 1 : 0;

if (inToolbar != _inToolbar)
	cs("breadCrumbs", inToolbar);

if (inToolbar)
{
	//set link on logo to home page
	document.getElementsByClassName("navbar-header")[0].getElementsByTagName("a")[0].setAttribute("href", "../");

	//insert breadcrumbs to top toolbar
	_$("search").parentNode.insertBefore(bc[0], _$("search").nextSibling);
	css = function(){/*
/* center breadcrumbs in the toolbar *//*
.btn-breadcrumb
{
    margin-top: 8px;
    margin-left: -10px;
}

/* move everything else down *//*
#content-wrapper
{
	margin-top: 40px;
}
*/};
}
else
{
	css = function(){/*
/* disallow menu bar wrap if it doesn't fit into window *//*
.navbar-fixed-top
{
	max-height: 50px;
}

/* move everything else down *//*
#content-wrapper
{
	margin-top: 50px;
}

/* make breadcrumbs at fixed position so it always visible *//*
.btn-breadcrumb
{
	position: fixed;
	z-index: 9999;
}
*/};
}

style.innerHTML = css.toString().slice(14,-3).split("*//*").join("*/");
document.getElementsByTagName("head")[0].appendChild(style);

//latest beta
let nav, ul, lis;
if ((nav = document.evaluate('.//nav[@class="navbar navbar-default navbar-fixed-bottom hidden-sm hidden-xs"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0))
		&& (ul = nav.getElementsByTagName("ul")[0])
		&& (lis = ul.getElementsByTagName("li")).length)
{
	let li = document.createElement("li"),
			a = document.createElement("a");

	li.appendChild(a);
	a.href = "http://t1.daumcdn.net/potplayer/beta/PotPlayerSetup.exe";
	a.innerHTML = '<i class="fa fa-download"></i> Latest Beta';
	ul.appendChild(li);
}

//auto login checkbox
let pass = _$("navloginform"),
		found = false;

if (pass)
{
	let inputs = pass.getElementsByTagName("input");

	for(let i = 0; i < inputs.length; i++)
	{
		if (inputs[i].name == "autologin")
			found = i;

		if (inputs[i].name == "password")
			pass = inputs[i];
	}
	if (found === false)
	{
		let checkbox = document.createElement("div");
		checkbox.className = "checkbox";
		checkbox.innerHTML = '<label for="autologin"><input name="autologin" id="autologin" tabindex="4" type="checkbox"> Log me on automatically each visit</label><br><label for="viewonline"><input name="viewonline" id="viewonline" tabindex="5" type="checkbox"> Hide my online status this session</label>';
		_$("navloginform").insertBefore(checkbox, pass.nextSibling);
	}
}

//private messages counter
try
{
	let numObj = document.getElementsByClassName("label label-primary"),
			btn = document.getElementsByClassName("btn btn-primary btn-labeled navbar-btn dropdown-toggle");
	if (numObj.length && btn.length)
	{
		numObj = numObj[0].getElementsByTagName("strong")[0].cloneNode(true);
		let num = parseInt(numObj.textContent),
				btnObj = btn[0].getElementsByClassName("btn-label")[0];

		numObj.style.paddingLeft = "5px";
		if (num > 0)
		{
			btn[0].className = btn[0].className.replace("btn-primary", "btn-danger");
			btnObj.appendChild(numObj);
		}
	}
}
catch(e)
{
	log(e);
}