TPC Sticky User Toolbar

Transforms "User Options" on the left sidebar into a toolbar that sticks to the top

目前為 2022-02-06 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        TPC Sticky User Toolbar
// @namespace   https://greasyfork.org/en/users/34131-velc-gf
// @version     1.0.5
// @description Transforms "User Options" on the left sidebar into a toolbar that sticks to the top
// @author      Velarde, Louie C.
// @include     https://tipidpc.com/*
// @icon        https://tipidpc.com/favicon.ico
// @grant       GM_addStyle
// @license     GNU LGPLv3
// ==/UserScript==

var userOptions = document.getElementById('user-options');
if (!userOptions) return;
userOptions.parentElement.removeChild(userOptions);

var userOptionsList = userOptions.getElementsByTagName('ul')[0];

userOptionsList.id = 'user-options-list';
GM_addStyle('#user-options-list {background-color:#E80; border-bottom:1px solid #333; box-sizing:border-box; padding:0.5em; top:0;}');
GM_addStyle('#user-options-list li {background-image:none; display:inline; margin-bottom:0;}');
GM_addStyle('#user-options-list li:last-of-type {float:right; margin-right:10px;}');
GM_addStyle('#user-options-list li a {color: #fff;}');

var container = document.getElementById('container');
var header = document.getElementById('header');

var anchor = document.createElement('div');
header.appendChild(anchor);
header.appendChild(userOptionsList);

var icon = (function() {
  var icon = document.createElement('img');
  icon.src = 'favicon.ico';
  icon.style.verticalAlign = 'middle';

  var link = document.createElement('a');
  link.href = '/index.php';
  link.style.marginLeft = '10px';

  link.appendChild(icon);
  return link;
})();

function updateUserOptionsListPosition() {
  var scrolledAmount = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  if (scrolledAmount > anchor.offsetTop) {
    if (userOptionsList.style.position != 'fixed') {
      userOptionsList.style.position = 'fixed';
      anchor.style.height = userOptionsList.offsetHeight + 'px';
      // userOptionsList.insertBefore(icon, userOptionsList.children[0]);
    }
  } else {
    if (userOptionsList.style.position != 'static') {
      userOptionsList.style.position = 'static';
      anchor.style.height = '0';
      // userOptionsList.removeChild(icon);
    }
  }
}

function updateUserOptionsListWidth() {
	userOptionsList.style.width = container.offsetWidth + 'px';
}

if (window.addEventListener) {
	window.addEventListener('scroll', updateUserOptionsListPosition);
	window.addEventListener('resize', updateUserOptionsListWidth);
} else {
	window.attachEvent('onscroll', updateUserOptionsListPosition);
	window.attachEvent('onresize', updateUserOptionsListWidth);
}

updateUserOptionsListPosition();
updateUserOptionsListWidth();