Skip to content

Commit

Permalink
feat: 编辑课程名称 (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: CJJ-amateur-programmer <[email protected]>
  • Loading branch information
YDX-2147483647 and CJJ-amateur-programmer authored Mar 4, 2024
1 parent 795a400 commit 4697776
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion TamperMonkey/BIT-乐学-修改侧边栏课程-GUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
-**更新课程并修改侧边栏**”将发送网络请求并获取最新的课程情况,列在“显示的课程”一栏;
-**仅修改侧边栏**”则从本地篡改猴储存中获取课程情况。

此外在弹窗中双击格子,还可**编辑课程名称**(粘贴文本时会自动去除换行和格式)。完成后请按<kbd>Enter</kbd>或者单击旁边空白处来退出编辑模式。

## 兼容性

这段脚本与“[BIT-乐学-修改侧边栏课程](https://greasyfork.org/scripts/470832)”矛盾,同时启用时效果不确定。

- 此脚本的操作方式远比无GUI版直观,直接拖动即可;
- 无GUI版能修改名称、图标,此脚本目前还不能。
- 无GUI版能修改图标,此脚本目前还不能。

欢迎有志之士前往 [YDX-2147483647/BIT-enhanced](https://github.com/YDX-2147483647/BIT-enhanced) 帮忙合并两段脚本。
29 changes: 25 additions & 4 deletions TamperMonkey/BIT-乐学-修改侧边栏课程-GUI.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name BIT-乐学-修改侧边栏课程-GUI
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @version 0.1.2
// @description 修改侧边栏显示的课程
// @license GPL-3.0-or-later
// @supportURL https://github.com/YDX-2147483647/BIT-enhanced/issues
Expand All @@ -26,7 +26,7 @@
popup_cover.style = 'width:100%;height:100%;background-color:rgba(0,0,0,0.6);position:fixed;inset:0px;z-index:2000'

function rewrite_sidebar (shown_courses) {
const current_id = (location.href.match(/(?<=id=)\w+/) || [])[0]
const current_id = (document.querySelector('[data-key="coursehome"].active_tree_node')?.href?.match(/(?<=id=)\w+/) || [])[0]
const mycourses = document.querySelector('li:has([data-key="mycourses"])')
const sidebar_course_list = mycourses.parentNode

Expand Down Expand Up @@ -116,6 +116,9 @@ ul#shown_courses>li,ul#hidden_courses>li,div.table-title{
width: 100%;
text-align: center;
}
span[contenteditable='true']{
border:thin solid #C0C0C0;
}
</style><div id="popup_title">编辑侧边栏课程
<div id="close_popup">×</div>
</div>
Expand Down Expand Up @@ -180,7 +183,16 @@ ul#shown_courses>li,ul#hidden_courses>li,div.table-title{
}
}
})
shown_li.innerHTML = `<a class="list-group-item list-group-item-action"><div class="ml-1"><div class="media"><span class="media-body">${shown_courses[i][1]}</span></div></div></a>`
shown_li.innerHTML =
`<a class="list-group-item list-group-item-action">
<div class="ml-1">
<div class="media">
<span class="media-body" ondblclick="this.setAttribute('contenteditable','true');this.focus()" onblur="this.removeAttribute('contenteditable')" onkeydown="if(event.keyCode===13){this.blur()}" onpaste="event.preventDefault();document.execCommand('insertText',false,event.clipboardData.getData('text/plain').replace(/[\\n|\\r]/gm,''))">
${shown_courses[i][1]}
</span>
</div>
</div>
</a>`
popup.querySelector('#shown_courses').append(shown_li)
}
for (let j = 0; j < hidden_courses.length; j++) {
Expand All @@ -203,7 +215,16 @@ ul#shown_courses>li,ul#hidden_courses>li,div.table-title{
}
}
})
hidden_li.innerHTML = `<a class="list-group-item list-group-item-action"><div class="ml-1"><div class="media"><span class="media-body">${hidden_courses[j][1]}</span></div></div></a>`
hidden_li.innerHTML =
`<a class="list-group-item list-group-item-action">
<div class="ml-1">
<div class="media">
<span class="media-body" ondblclick="this.setAttribute('contenteditable','true');this.focus()" onblur="this.removeAttribute('contenteditable')" onkeydown="if(event.keyCode===13){this.blur()}" onpaste="event.preventDefault();document.execCommand('insertText',false,event.clipboardData.getData('text/plain').replace(/[\\n|\\r]/gm,''))">
${hidden_courses[j][1]}
</span>
</div>
</div>
</a>`
popup.querySelector('#hidden_courses').append(hidden_li)
}
document.body.append(popup_cover)
Expand Down
2 changes: 1 addition & 1 deletion TamperMonkey/BIT-乐学-修改侧边栏课程.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

这段脚本与“[BIT-乐学-修改侧边栏课程-GUI](https://greasyfork.org/zh-CN/scripts/488788)”矛盾,同时启用时效果不确定。

- 此脚本能修改名称、图标,GUI版目前还不能;
- 此脚本能修改图标,GUI版目前还不能;
- GUI版的操作方式远比此脚本直观,直接拖动即可;

欢迎有志之士前往 [YDX-2147483647/BIT-enhanced](https://github.com/YDX-2147483647/BIT-enhanced) 帮忙合并两段脚本。

0 comments on commit 4697776

Please sign in to comment.