Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63a7962

Browse files
committed
Update to Link Gopher 2.0beta1
This work was done by a contractor. I would mention his name, buthe was "not very happy with the result."
1 parentb282d50 commit63a7962

18 files changed

+361
-261
lines changed

‎_locales/en/messages.json‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"askPattern": {
3+
"message":"Enter a string of characters to search for within the link. Links without this string will be ignored.",
4+
"description":"none"
5+
},
6+
7+
"pleaseWait": {
8+
"message":"Please wait...",
9+
"description":"none"
10+
},
11+
12+
"links": {
13+
"message":"Links",
14+
"description":"none"
15+
},
16+
17+
"domains": {
18+
"message":"Domains",
19+
"description":"none"
20+
},
21+
22+
"noMatches": {
23+
"message":"No matches",
24+
"description":"none"
25+
},
26+
27+
"extractAll": {
28+
"message":"Extract All Links",
29+
"description":"none"
30+
},
31+
32+
"extractSome": {
33+
"message":"Extract Links by Filter",
34+
"description":"none"
35+
},
36+
37+
"aboutLinkGopher": {
38+
"message":"About Link Gopher",
39+
"description":"none"
40+
}
41+
}

‎browser/css/linkgopher.css‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#links:not(:empty)::before,
2+
#domains:not(:empty)::before {
3+
content:attr(data-content);
4+
display: block;
5+
font-weight: bold;
6+
margin-bottom:1em;
7+
}
8+
9+
#domains {
10+
margin-top:2em;
11+
}
12+
13+
#message::before {
14+
content:attr(data-content);
15+
}
16+
17+
#links:not(:empty)~#message,
18+
#domains:not(:empty)~#message {
19+
display: none;
20+
}

‎browser/js/linkgopher.js‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict';
2+
constcontainerLinks=document.getElementById('links');
3+
constcontainerDomains=document.getElementById('domains');
4+
constmessage=document.getElementById('message');
5+
constreBaseURL=/(^\w+:\/\/[^\/]+)|(^[A-Za-z0-9.-]+)\/|(^[A-Za-z0-9.-]+$)/;
6+
consttabId=parseInt(location.search.replace(/.*tabId=(\d+).*/,'$1'));
7+
constfiltering=location.search.replace(/.*filtering=(true|false).*/,'$1');
8+
constpattern=filtering==='true'
9+
?window.prompt(chrome.i18n.getMessage('askPattern'))
10+
:null;
11+
constfilteringDomains=location
12+
.search.replace(/.*filteringDomains=(true|false).*/,'$1')==='true'
13+
?true
14+
:false;
15+
16+
chrome.tabs.sendMessage(tabId,{action:'extract'},links=>{
17+
handler(links,pattern);
18+
});
19+
20+
// Localization.
21+
[
22+
{id:'links',messageId:'links'},
23+
{id:'domains',messageId:'domains'},
24+
{id:'message',messageId:'pleaseWait'}
25+
].forEach(item=>{
26+
constcontainer=document.getElementById(item.id);
27+
container.dataset.content=chrome.i18n.getMessage(item.messageId);
28+
})
29+
30+
/**
31+
*@function handler
32+
*@param {array} urls -- Array of links.
33+
*@param {string} pattern -- Pattern for filtering.
34+
*/
35+
functionhandler(links,pattern){
36+
if(chrome.runtime.lastError){
37+
returnwindow.alert(chrome.runtime.lastError);
38+
}
39+
40+
// To filter links like: #"diff-1a5ca4515dfcfba136b0979fe09def66579d8cc6afcb3e67424908a397fba6df-empty-41-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
41+
constresLinks=links.filter(link=>link.lastIndexOf('://',10)>0);
42+
// Remove duplicate, sorting of links.
43+
constitems=[...(newSet(resLinks))].sort();
44+
constre=pattern ?newRegExp(pattern,'g') :null;
45+
constadded=items.filter(link=>addNodes(link,containerLinks,re));
46+
47+
if(!added.length){
48+
returnmessage.dataset.content=chrome.i18n.getMessage('noMatches');
49+
}
50+
// Extract base URL from link, remove duplicate, sorting of domains.
51+
constdomains=[...(newSet(added.map(link=>getBaseURL(link))))].sort();
52+
constreDomains=filteringDomains ?re :null;
53+
domains.forEach(domain=>addNodes(domain,containerDomains,reDomains));
54+
};
55+
56+
/**
57+
* Add nodes to container.
58+
*
59+
*@function addNodes
60+
*@param {string} link
61+
*@param {Node} container
62+
*@param {object|null} re -- Regular Expression pattern.
63+
*@return {boolean} -- Whether link added into document.
64+
*/
65+
functionaddNodes(url,container,re){
66+
if(re&&!url.match(re))returnfalse;
67+
68+
constbr=document.createElement('br');
69+
consta=document.createElement('a');
70+
a.href=url;
71+
a.innerText=url;
72+
container.appendChild(a);
73+
container.appendChild(br);
74+
75+
returntrue;
76+
};
77+
78+
/**
79+
* Get base URL of link.
80+
*
81+
*@function getBaseURL
82+
*@param {string} link
83+
*/
84+
functiongetBaseURL(link){
85+
constresult=link.match(reBaseURL);
86+
87+
if(!result){
88+
returnnull;
89+
}elseif(result[1]){
90+
return`${result[1]}/`;
91+
}else{
92+
return`http://${result[2]||result[3]}/`;
93+
}
94+
};

‎browser/linkgopher.html‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<metacharset="utf-8">
5+
<title>Link Gopher</title>
6+
<linkrel="stylesheet"href="css/linkgopher.css">
7+
</head>
8+
<body>
9+
<divid="links"data-content="Links"></div>
10+
<divid="domains"data-content="Domains"></div>
11+
<h2id="message"data-content="Please wait..."></h2>
12+
13+
<scriptsrc="js/linkgopher.js"charset="utf-8"></script>
14+
</body>
15+
</html>

‎chrome.manifest‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎chrome/content/extract-links.js‎

Lines changed: 0 additions & 189 deletions
This file was deleted.

‎chrome/content/link-gopher.xul‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎chrome/locale/en-US/link-gopher-menu.dtd‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp