Bugzilla - reveal the Depends, Blocks, See Also and Duplicates bug titles

Reveal the Depends, Blocks, See Also and Duplicates bug titles in bugzilla.mozilla.org via keyboard shortcuts

目前為 2020-06-25 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Bugzilla - reveal the Depends, Blocks, See Also and Duplicates bug titles
// @namespace   darkred
// @version     2017.16.11
// @description Reveal the Depends, Blocks, See Also and Duplicates bug titles in bugzilla.mozilla.org via keyboard shortcuts
// @license     MIT
// @include     https://bugzilla.mozilla.org/show_bug.cgi?id=*
// @grant       none
// @require     https://code.jquery.com/jquery-3.2.1.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/jquery-scrollTo/2.1.2/jquery.scrollTo.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/keypress/2.1.3/keypress.min.js
// @supportURL  https://github.com/darkred/Userscripts/issues
// ==/UserScript==

/* eslint-disable no-unused-vars */

// Case 1: when you press ` (in order to toggle Depends, BLocks and See Also)

var flag1 = 1;
var listener1 = new window.keypress.Listener();
var listener2 = new window.keypress.Listener();
var depends, blocks, combinedRefs, seeAlsoRefs, duplicatesRefs;

var combinedInners = [], seeAlsoInners = [], duplicatesInners = [];

listener1.simple_combo('`', function() {
	// console.log('You pressed `');

	depends = $('#field-value-dependson > a');
	blocks = $('#field-value-blocked > a');
	seeAlsoRefs = $('#field-value-see_also a');
	combinedRefs = depends.add(blocks).add(seeAlsoRefs);


	if (flag1 === 1) {
		flag1 = 0;

		$(window).scrollTo('#field-dependson');

		$.each(combinedRefs, function(index, val) {	combinedInners[index] = combinedRefs[index].innerHTML;});

		$.each(combinedRefs, function(index, val) {
			combinedRefs[index].nextSibling.remove();
			combinedRefs[index].innerHTML = '(' + combinedRefs[index].innerHTML + ')  ' + combinedRefs[index].title;
			combinedRefs[index].outerHTML += '<br/>';
		});


	} else {
		if (flag1 === 0) {
			flag1 = 1;

			$.each(combinedRefs, function(index, val) {
				combinedRefs[index].innerHTML = combinedInners[index];
				combinedRefs[index].outerHTML += ', ';
			});

			var dependsNL = $('#field-value-dependson > a ~ br');
			var blocksNL = $('#field-value-blocked > a ~ br');

			var combinedNL = dependsNL.add(blocksNL);
			for (let m = (combinedNL.length) - 1; m >= 0; m -= 1) {
				combinedNL[m].remove();
			}

		}
		document.body.scrollTop = document.documentElement.scrollTop = 0;           // scroll to the top of the page
		// window.scrollTo(0, 0);
		// document.querySelector('html').scrollIntoView();

		// $(window).scrollTo('#field-see_also');
		$(window).scrollTo('#field-dependson');  // alternative to line 78
	}
});


// =========================================================================


// Case 2: when you press ~ (in order to toggle Duplicates)

var flag2 = 1;

listener2.simple_combo('~', function() {
	// console.log('You pressed ~');

	duplicatesRefs = $(`a:contains('Duplicates')`).parent().parent().find('.value > a');

	if (flag2 === 1) {
		flag2 = 0;

		// $(window).scrollTo('#duplicates');
		$(window).scrollTo(`a:contains('Duplicates')`).parent().parent();

		$.each(duplicatesRefs, function(index, val) {	duplicatesInners[index] = duplicatesRefs[index].innerHTML;});

		$.each(duplicatesRefs, function(index, val) {
			duplicatesRefs[index].nextSibling.remove();
			duplicatesRefs[index].innerHTML = '(' + duplicatesRefs[index].innerHTML + ')  ' + duplicatesRefs[index].title;
			duplicatesRefs[index].outerHTML += '<br/>';
		});

	} else {
		if (flag2 === 0) {
			flag2 = 1;

			$.each(duplicatesRefs, function(index, val) {
				duplicatesRefs[index].innerHTML = duplicatesInners[index];
				duplicatesRefs[index].outerHTML += ', ';
			});


			var duplicatesNL = $(`a:contains('Duplicates')`).parent().parent().find('.value > a ~ br');
			for (let k = (duplicatesNL.length) - 1; k >= 0; k -= 1) {
				duplicatesNL[k].remove();
			}

		}

		// document.body.scrollTop = document.documentElement.scrollTop = 0;           // scroll to the top of the page
		window.scrollTo(0, 0);
		// document.querySelector('html').scrollIntoView();
		// $(window).scrollTo('#duplicates');
		$(window).scrollTo(`a:contains('Duplicates')`).parent().parent();
	}
});