Created
September 8, 2022 05:39
-
-
Save costdev/ac8eddf49dcd7ac6b6eae9a8ae517497 to your computer and use it in GitHub Desktop.
Revised Core Trac "New Ticket" screen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Core Trac <New Ticket> | |
// @version 1.0.0 | |
// @description Clean up Core Trac <New Ticket> page. | |
// @author costdev | |
// @homepage https://github.com/costdev | |
// @match https://core.trac.wordpress.org/newticket | |
// @icon https://core.trac.wordpress.org/chrome/common/trac.ico | |
// @grant none | |
// ==/UserScript== | |
( function ( $ ) { | |
'use strict'; | |
$( 'html' ).css( 'overflow-y', 'scroll' ); | |
var ntnh = $( '.newticket-not-here' ); | |
if ( ntnh.length ) { | |
add_existing_tickets_notice(); | |
hide_instructions_and_form(); | |
add_issue_menu(); | |
add_link_event_handlers(); | |
respect_url_anchor(); | |
$( ntnh ).remove(); | |
} | |
function add_existing_tickets_notice() { | |
$( '.ticket h1' ).after( '<div class="wp-notice"></div>' ); | |
$( '.ticket .wp-notice' ).append( $( '.newticket-instructions p:last-child' ) ); | |
$( '.newticket-instructions li:last-child' ).remove(); | |
} | |
function hide_instructions_and_form() { | |
$( '.newticket-instructions, .ticket form' ).hide(); | |
$( '.newticket-instructions strong' ).remove(); | |
} | |
function add_issue_menu() { | |
$( ntnh ).after( ` | |
<style> | |
.ticket .nav ul { | |
display: flex; | |
float: none !important; | |
gap: 1rem; | |
justify-content: space-between; | |
margin-block: 1rem; | |
width: 100%; | |
} | |
@media (max-width: 1024px) { | |
.ticket .nav ul { | |
display: grid; | |
grid-template-columns: repeat( auto-fit, minmax( 160px, 1fr ) ); | |
} | |
} | |
.ticket .nav li { | |
flex-grow: 1; | |
float: none !important; | |
text-align: center; | |
} | |
.ticket .nav li.active .button { | |
background: #0073aa !important; | |
box-shadow: inset 0 2px 0 #006799 !important; | |
} | |
@media (max-width: 1024px) { | |
.ticket .nav li { | |
flex-grow: 0; | |
} | |
} | |
.ticket .nav .create-new-ticket { | |
clear: none; | |
display: block; | |
float: none; | |
margin: 0 !important; | |
padding: 0; | |
} | |
.ticket .nav a { | |
font-size: 13px; | |
height: auto; | |
line-height: normal; | |
margin: 0; | |
padding: 10px !important; | |
width: auto; | |
} | |
</style> | |
<div id="mainnav" class="nav"> | |
<ul> | |
<li> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="https://wordpress.org/support/forums/">Support request</a> | |
</span> | |
</li> | |
<li> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="https://make.wordpress.org/core/handbook/reporting-security-vulnerabilities/">Security vulnerability</a> | |
</span> | |
</li> | |
<li class="openform"> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="#bug">Bug</a> | |
</span> | |
</li> | |
<li class="openform"> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="#enhancement">Enhancement</a> | |
</span> | |
</li> | |
<li class="openform"> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="#feature-request">Feature request</a> | |
</span> | |
</li> | |
<li class="openform"> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="#task">Task</a> | |
</span> | |
</li> | |
<li> | |
<span class="create-new-ticket button button-large button-primary"> | |
<a href="https://github.com/WordPress/gutenberg/issues/" data-type='task'>Gutenberg</a> | |
</span> | |
</li> | |
</ul> | |
</div>` | |
); | |
} | |
function add_link_event_handlers() { | |
$( '.ticket a' ).on( 'click', function(e) { | |
toggle_active_link( e ); | |
handle_external_links( e ); | |
} ); | |
$( '.ticket .openform a' ).on( 'click', handle_form_links ); | |
} | |
function toggle_active_link( e ) { | |
e.preventDefault(); | |
$( '.ticket li.active' ).removeClass( 'active' ); | |
$( e.target ).parents( 'li' ).addClass( 'active' ); | |
} | |
function handle_external_links( e ) { | |
if ( ! $( e.target ).parents( 'li' ).hasClass( 'openform' ) ) { | |
window.location.href = $( e.target ).attr( 'href' ); | |
} | |
} | |
function handle_form_links( e ) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
var item = $( e.target ); | |
$( '[name="field_summary"]' ).attr( 'autocomplete', 'off' ); | |
$( '.newticket-instructions' ).hide(); | |
var summary = '', | |
slug = item.text().toLowerCase(), | |
type = slug; | |
switch( slug ) { | |
case 'bug': | |
$( '.newticket-instructions' ).show(); | |
type = 'defect (bug)'; | |
break; | |
case 'feature request': | |
summary = 'Feature Request: '; | |
break; | |
case 'task': | |
summary = 'Task: '; | |
type = 'task (blessed)'; | |
break; | |
} | |
$( '[name="field_summary"]' ).val( summary ); | |
$( '[name="field_type"]' ).val( type ); | |
$( '.ticket form' ).show(); | |
$( '[name="field_summary"]' ).focus(); | |
window.location.hash = slug.replace( ' ', '-' ); | |
} | |
function respect_url_anchor() { | |
var hash = window.location.hash; | |
if ( hash ) { | |
$( '.ticket .nav a' ).each( function() { | |
if ( $( this ).text().toLowerCase().replace( ' ', '-' ) === hash.substr( 1, hash.length ) ) { | |
$( this ).click(); | |
} | |
} ); | |
} | |
} | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment