Skip to content

Instantly share code, notes, and snippets.

@rexxiang
Created November 19, 2024 03:34
Show Gist options
  • Save rexxiang/00707a79d83480d9d1dc8527d73f381f to your computer and use it in GitHub Desktop.
Save rexxiang/00707a79d83480d9d1dc8527d73f381f to your computer and use it in GitHub Desktop.

Revisions

  1. rexxiang created this gist Nov 19, 2024.
    74 changes: 74 additions & 0 deletions xxl-job-enhancer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    // ==UserScript==
    // @name XXL-Job enhancer
    // @namespace http://tampermonkey.net/
    // @version 2024-11-19
    // @description xxl-job enhancer
    // @author You
    // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
    // @grant none

    // @match *://**/*xxljob*/jobinfo*
    // @match *://**/*xxl-job*/jobinfo*

    // @match *://**/*xxljob*/joblog*
    // @match *://**/*xxl-job*/joblog*

    // ==/UserScript==

    (function() {
    'use strict';
    const JOB_GROUP = 'jobGroup'

    const pathname =window.location.pathname.split('/').pop()
    const queries = new URLSearchParams(window.location.search);
    const gid = queries.get(JOB_GROUP)
    if (gid) {
    window.localStorage.setItem(JOB_GROUP, gid)

    document.querySelectorAll('aside > section > ul > li.nav-click > a').forEach(e => {
    const href = e.getAttribute('href')
    if (href && (href.endsWith('jobinfo') || href.endsWith('joblog'))) {
    e.setAttribute('href', href + '?' + queries.toString())
    }
    })
    } else {
    const g = window.localStorage.getItem(JOB_GROUP)
    if (g) {
    queries.set(JOB_GROUP, g)
    window.location.search = '?' + queries.toString()
    }
    }

    // replace operation button
    if ($) {
    $(document).on('ajaxSuccess', function() {
    document.querySelectorAll('table.table > tbody > tr > td:last-child > div').forEach((e) => {
    const b1 = e.querySelector(':first-child');
    if (b1) { b1.remove() }

    const b2 = e.querySelector(':first-child');
    if (b2) { b2.prepend(document.createTextNode('操作')) }
    })
    })
    }

    if (pathname === 'joblog') {
    const select = document.querySelector('#jobGroup')
    if (gid) {
    const g = select.querySelector('option[value="' + gid + '"]')
    if (g) { g.selected = 'selected' }

    document.querySelector('#searchBtn').click()
    }

    if (select) {
    select.addEventListener('change', () => {
    if (select.value) {
    queries.set(JOB_GROUP, select.value)
    window.location.search = '?' + queries.toString()
    }
    })
    }
    }

    })();