Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
safelinks-cleaner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
safelinks
safelinks-cleaner
Commits
450bc415
Commit
450bc415
authored
4 years ago
by
David Byers
Browse files
Options
Downloads
Patches
Plain Diff
Added support for unmangling links on compose.
parent
291bfb6f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#32533
passed
4 years ago
Stage: build
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
extension/background.js
+8
-5
8 additions, 5 deletions
extension/background.js
extension/common.js
+20
-0
20 additions, 0 deletions
extension/common.js
extension/display.js
+0
-20
0 additions, 20 deletions
extension/display.js
extension/manifest.json
+2
-1
2 additions, 1 deletion
extension/manifest.json
with
30 additions
and
26 deletions
extension/background.js
+
8
−
5
View file @
450bc415
browser
.
composeScripts
.
register
({
js
:
[
{
file
:
"
common.js
"
},
{
file
:
"
compose.js
"
}
],
});
browser
.
messageDisplayScripts
.
register
({
css
:
[
{
file
:
"
/style.css
"
}
],
js
:
[
{
file
:
"
/common.js
"
},
{
file
:
"
/
content
.js
"
}
{
file
:
"
/
display
.js
"
}
],
});
console
.
log
(
browser
);
console
.
log
(
browser
.
i18n
);
browser
.
menus
.
create
({
id
:
"
liu-safelinks-copy
"
,
title
:
browser
.
i18n
.
getMessage
(
"
copyLinkMenuTitle
"
),
...
...
This diff is collapsed.
Click to expand it.
extension/common.js
+
20
−
0
View file @
450bc415
...
...
@@ -19,3 +19,23 @@ function untangleLink(link) {
function
isTangledLink
(
link
)
{
return
link
.
match
(
safelinksRegexp
);
}
function
getTextNodes
(
elem
)
{
var
result
=
[];
if
(
elem
)
{
for
(
var
nodes
=
elem
.
childNodes
,
i
=
nodes
.
length
;
i
--
;)
{
let
node
=
nodes
[
i
];
let
nodeType
=
node
.
nodeType
;
if
(
nodeType
==
Node
.
TEXT_NODE
)
{
result
.
push
(
node
);
}
else
if
(
nodeType
==
Node
.
ELEMENT_NODE
||
nodeType
==
Node
.
DOCUMENT_NODE
||
nodeType
==
Node
.
DOCUMENT_FRAGMENT_NODE
)
{
result
=
result
.
concat
(
getTextNodes
(
node
));
}
}
}
return
result
;
}
This diff is collapsed.
Click to expand it.
extension/
content
.js
→
extension/
display
.js
+
0
−
20
View file @
450bc415
// Modify the displayed message to clarify where safelinks are
// inserted and to show the actual link targets.
function
getTextNodes
(
elem
)
{
var
result
=
[];
if
(
elem
)
{
for
(
var
nodes
=
elem
.
childNodes
,
i
=
nodes
.
length
;
i
--
;)
{
let
node
=
nodes
[
i
];
let
nodeType
=
node
.
nodeType
;
if
(
nodeType
==
Node
.
TEXT_NODE
)
{
result
.
push
(
node
);
}
else
if
(
nodeType
==
Node
.
ELEMENT_NODE
||
nodeType
==
Node
.
DOCUMENT_NODE
||
nodeType
==
Node
.
DOCUMENT_FRAGMENT_NODE
)
{
result
=
result
.
concat
(
getTextNodes
(
node
));
}
}
}
return
result
;
}
for
(
const
link
of
document
.
links
)
{
// Mangle the link text
for
(
const
node
of
getTextNodes
(
link
))
{
...
...
This diff is collapsed.
Click to expand it.
extension/manifest.json
+
2
−
1
View file @
450bc415
...
...
@@ -27,6 +27,7 @@
"permissions"
:
[
"messagesModify"
,
"clipboardWrite"
,
"menus"
"menus"
,
"compose"
]
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment