Skip to content

Commit 49048fd

Browse files
committed
✨ 增加清除全部辅助线的功能
1 parent dd3c148 commit 49048fd

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

popup.html

+23-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<div class="glgl-main-box">
77
<div class="glgl-popup-page-button" id="add-vertical-line">添加纵向辅助线</div>
88
<div class="glgl-popup-page-button" id="add-horizontal-line">添加横向辅助线</div>
9-
<i style="padding-top: 40px; color: gray;">更多功能开发中...</i>
9+
<div class="glgl-popup-page-button-warning" id="remove-all-lines">清空全部辅助线</div>
10+
<i style="padding-top: 26px; color: gray;">更多功能开发中...</i>
1011
</div>
1112
</body>
1213

@@ -42,5 +43,26 @@
4243
background-color: #e1e1e1;
4344
cursor: pointer;
4445
}
46+
47+
.glgl-popup-page-button-warning{
48+
width: 100%;
49+
height: 30px;
50+
51+
background-color: #fdfdfd;
52+
53+
border-radius: 5px;
54+
font-size: 1.2em;
55+
56+
margin-bottom: 10px;
57+
58+
display: flex;
59+
justify-content: center;
60+
align-items: center;
61+
}
62+
63+
.glgl-popup-page-button-warning:hover{
64+
background-color: #FF9090;
65+
cursor: pointer;
66+
}
4567
</style>
4668
</html>

script/actions/addHorizontalLine.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ function addHorizontalLine() {
22
const bodyDom = document.body
33
const horizontalLineBgId = `gagl-horizontal-line-bg`
44
const horizontalLineId = `gagl-horizontal-line`
5-
5+
const gaglLineBgClass = `gagl-line-bg`
6+
67
let mouseIsDown = false
78

89
const horizontalLineBgMouseOverEvent = () => {
@@ -29,6 +30,7 @@ function addHorizontalLine() {
2930
const horizontalLineBg = document.createElement('div')
3031

3132
horizontalLineBg.id = horizontalLineBgId
33+
horizontalLineBg.className = gaglLineBgClass
3234

3335
horizontalLineBg.style.width = '100vw'
3436
horizontalLineBg.style.height = '16px'

script/actions/addVerticalLine.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ function addVerticalLine() {
22
const bodyDom = document.body
33
const verticalLineBgId = `gagl-vertical-line-bg`
44
const verticalLineId = `gagl-vertical-line`
5+
const gaglLineBgClass = `gagl-line-bg`
56

67
let mouseIsDown = false
78

@@ -29,6 +30,7 @@ function addVerticalLine() {
2930
const verticalLineBg = document.createElement('div')
3031

3132
verticalLineBg.id = verticalLineBgId
33+
verticalLineBg.className = gaglLineBgClass
3234

3335
verticalLineBg.style.width = '16px'
3436
verticalLineBg.style.height = '100vh'

script/actions/removeAllLines.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async function removeAllLines() {
2+
const gaglLineBgClass = `gagl-line-bg`
3+
const lineDoms = await document.getElementsByClassName(gaglLineBgClass)
4+
if (lineDoms && lineDoms.length > 0) {
5+
const lineDOmsArray = []
6+
for(let i = 0; i < lineDoms.length; i++) {
7+
lineDOmsArray.push(lineDoms[i])
8+
}
9+
if (lineDOmsArray && lineDOmsArray.length > 0) {
10+
for (let j = 0; j < lineDOmsArray.length; j++) {
11+
lineDOmsArray[j].remove()
12+
}
13+
}
14+
}
15+
}
16+
17+
removeAllLines()

script/popup.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const getCurrentTab = async () => {
77

88
const getCurrentTabId = async () => {
99
const currentTab = await getCurrentTab()
10-
console.log('currentTab', currentTab)
1110
if (currentTab && currentTab.id) {
1211
return currentTab.id
1312
} else {
@@ -47,3 +46,22 @@ if (addHorizontalLineButton) {
4746
addHorizontalLineButton.addEventListener('click', addHorizontalLineOnYourPage)
4847
}
4948

49+
50+
const removeAllLines = () => {
51+
getCurrentTabId().then(currentTabId => {
52+
chrome.scripting.executeScript({
53+
target : {tabId : currentTabId},
54+
files : [ "script/actions/removeAllLines.js" ],
55+
})
56+
.then(() => console.log("removeAllLines script injected"));
57+
})
58+
}
59+
60+
const removeAllLinesButton = document.getElementById('remove-all-lines')
61+
if (removeAllLinesButton) {
62+
removeAllLinesButton.addEventListener('click', removeAllLines)
63+
}
64+
65+
66+
67+

0 commit comments

Comments
 (0)