Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
songxingling1 committed Dec 15, 2024
0 parents commit f4d63dc
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
dist
1 change: 1 addition & 0 deletions assets/message.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.top-bar #luogu_popwindow_setting {
margin-right: 8pt;
}

#luogu_popwindow_setting:not(.top-bar *) {
margin-right: 5pt;
}
#luogu_popwindow_setting:not(.top-bar *,.link-container + .user-nav *) {
color: inherit;
}
.top-bar .user-nav > #luogu_popwindow_setting:hover {
background-color: rgba(0, 0, 0, .05);
padding: 3pt 3pt 3pt 3pt;
margin-right: 5pt;
border-radius: 3px
}

#luogu_popwindow_setting:hover > svg > path {
fill: #0366d6;
}
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Luogu_Popwindow",
"version": "1.0.2",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sxl701817",
"license": "MIT",
"description": "洛谷弹窗",
"dependencies": {
"css-loader": "^7.1.2",
"path": "^0.12.7",
"style-loader": "^4.0.0",
"webpack": "^5.97.1",
"webpack-cil": "^0.0.1-security"
},
"devDependencies": {
"jquery": "^3.7.1",
"sweetalert2": "^11.15.0",
"webpack-cli": "^5.1.4"
}
}
17 changes: 17 additions & 0 deletions src/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ==UserScript==
// @name Luogu Popwindow
// @namespace http://tampermonkey.net/
// @version 1.0.2
// @description 洛谷弹窗
// @author sxl701817
// @match https://www.luogu.com.cn/*
// @icon https://s21.ax1x.com/2024/12/14/pAqEr9S.png
// @resource sweetcss https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.14.5/sweetalert2.min.css
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.14.5/sweetalert2.min.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_getResourceText
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
16 changes: 16 additions & 0 deletions src/listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let obs = new MutationObserver((muts,obs)=>{
muts.forEach((ele)=>{
if($('[currenttemplate="RecordShow"] section div .info-rows:last-child div:nth-child(2) span:last-child span').text().trim() === 'Accepted') {
swal.fire({
icon:"info",
title:"你通过了此题!",
html:GM_getValue('message','')
})
obs.disconnect()
}
})
});
export function startListen() {
let dom = document.querySelector('[currenttemplate="RecordShow"] section div .info-rows:last-child div:nth-child(2) span:last-child span')
obs.observe(dom,{characterData:true,attributes:true})
}
18 changes: 18 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import './../assets/style.css'
import $ from 'jquery'
import { startListen } from './listener'
import { makeAlert } from './settings'
let oldhref = 'kkkfc0114514'
let css = GM_getResourceText('sweetcss')
GM_addStyle(css)
setInterval(() => {
$(()=>{
if(window.location.href.search("https://www.luogu.com.cn/record/") === 0 && window.location.href !== oldhref) {
startListen()
}
if($('#luogu_popwindow_setting').length === 0) {
makeAlert()
}
oldhref = window.location.href
})
},200)
26 changes: 26 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import $ from 'jquery'
import swal from 'sweetalert2'
import icon from './../assets/message.svg'
export function makeAlert() {
let dom = `<a id="luogu_popwindow_setting" class="icon color-none">${icon}</a>`
$('.user-nav nav').prepend(dom)
$('.user-nav:has(> a)').prepend(dom)
$('#luogu_popwindow_setting').on('click',() => {
swal.fire({
icon:"question",
title:"请输入提示信息",
html:`<input type="text" value="${GM_getValue('message','')}" id="lgp_text" style="height:1.5em;width:21em;"></input>`,
showCancelButton: true
}).then((result)=>{
if(result.value) {
GM_setValue('message',$('#lgp_text').val())
swal.fire({
icon:"success",
title:"修改成功",
timer:1000,
showConfirmButton: false
})
}
})
})
}
31 changes: 31 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')
const webpack = require('webpack')
const fs = require('fs')
const header = fs.readFileSync('src/header.js').toString()
module.exports = {
entry:'./src/main.js',
module: {
rules:[
{
test: /\.css$/,
use: ['style-loader','css-loader']
},
{
test: /\.svg$/,
type: 'asset/source'
}
]
},
output: {
filename:'index.js',
path:path.resolve(__dirname,'dist')
},
optimization: {
minimize: false
},
externals: {
jquery:'jQuery',
sweetalert2:'Sweetalert2'
},
plugins:[new webpack.BannerPlugin({banner:header,raw:true})]
}

0 comments on commit f4d63dc

Please sign in to comment.