Skip to content

Commit

Permalink
Hide entries from linkchecker results
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp <[email protected]>
  • Loading branch information
Kiuryy committed Sep 22, 2021
1 parent 9c9992c commit 09395e5
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 44 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bookmark_sidebar",
"version": "1.21.0",
"versionName": "1.21.0",
"version": "1.22.0",
"versionName": "1.22.0",
"license": "GPL-3.0",
"author": "Philipp König",
"homepage": "https://extensions.redeviation.com/",
Expand All @@ -26,10 +26,10 @@
"html-minifier": "^4.0.0",
"jsonminify": "^0.4.1",
"node-sass": "^6.0.1",
"npm-check-updates": "^11.8.3",
"npm-check-updates": "^11.8.5",
"read-file": "^0.2.0",
"request": "^2.88.2",
"terser": "^5.7.1",
"terser": "^5.9.0",
"zip-dir": "^2.0.0"
}
}
104 changes: 77 additions & 27 deletions src/js/helper/linkchecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@
$("<a></a>").addClass($.cl.overlay.urlCheckAction).appendTo(elm);
});

$("<a></a>").addClass($.cl.overlay.urlCheckHide).appendTo(resultEntry);

ext.helper.model.call("favicon", {url: entry.url}).then((response) => { // retrieve favicon of url
if (response.img) { // favicon found -> add to entry
$("<img src='" + response.img + "' />").insertBefore(title);
Expand Down Expand Up @@ -273,6 +275,7 @@
}
});

$("<a></a>").addClass($.cl.overlay.urlCheckHide).appendTo(resultEntry);
$("<a></a>").addClass($.cl.overlay.urlCheckAction).appendTo(resultEntry);

ext.helper.model.call("favicon", {url: entry.url}).then((response) => { // retrieve favicon of url
Expand Down Expand Up @@ -326,14 +329,30 @@
elm.find("a." + $.cl.overlay.urlCheckAction).on("click", (e) => { // click on specific action button next to an entry in the list -> update only this entry
e.preventDefault();
const entry = $(e.currentTarget).parent("li");
const data = $(e.currentTarget).parent("li").data("entry");

const data = entry.data("entry");
entry.css("height", entry[0].offsetHeight + "px");

$.delay().then(() => {
entry.addClass($.cl.hidden);
updateEntry(data);
return Promise.all([
updateEntry(data),
$.delay(500)
]);
}).then(() => {
entry.remove();
updateResultPage();
});
});

elm.find("a." + $.cl.overlay.urlCheckHide).on("click", (e) => { // hide result from the list to never show again
e.preventDefault();
const entry = $(e.currentTarget).parent("li");
const data = entry.data("entry");
entry.css("height", entry[0].offsetHeight + "px");

$.delay().then(() => {
entry.addClass($.cl.hidden);
ignoreEntry(data);
return $.delay(500);
}).then(() => {
entry.remove();
Expand Down Expand Up @@ -375,6 +394,32 @@
}
};

/**
* Adds the given entry to the ignore list to not show it in any linkchecker results again
*
* @param {object} entry
*/
const ignoreEntry = (entry) => {
const ignoreList = ext.helper.model.getData("u/linkcheckerIgnored");
let key = entry.id;
const data = {type: "unknown"};

if (entry.broken) {
key = entry.url;
data.type = "broken";
} else if (entry.duplicates) {
key = entry.label;
data.type = "duplicate";
} else if (entry.url !== entry.newUrl) {
key = entry.url;
data.type = "outdated";
data.newUrl = entry.newUrl;
}

ignoreList[key] = data;
ext.helper.model.setData({"u/linkcheckerIgnored": ignoreList});
};

/**
* Updates the url of the given entry if it has changed or removes the entry, if the status code of the url checker is 404
*
Expand Down Expand Up @@ -499,14 +544,15 @@
let finished = 0;
const duplicateLabels = [];
const totalBookmarks = allBookmarks.length;
const ignoreList = ext.helper.model.getData("u/linkcheckerIgnored");

const checkChunk = (bookmarks) => {
return new Promise((rslv) => {
let resolved = 0;
for (const bookmark of bookmarks) {
let done = false;
const callback = () => {
if (done){
if (done) {
return;
}

Expand All @@ -529,34 +575,38 @@

if (response.duplicateInfo.duplicates.length > 0) {
if (duplicateLabels.indexOf(response.duplicateInfo.label) === -1) { // prevent multiple entries of the same url
results.duplicate.push({
label: response.duplicateInfo.label,
if (!ignoreList[response.duplicateInfo.label]) {
results.duplicate.push({
label: response.duplicateInfo.label,
url: bookmark.url,
duplicates: response.duplicateInfo.duplicates
});
duplicateLabels.push(response.duplicateInfo.label);
results.count++;
}
}
}

if (!ignoreList[bookmark.url]) {
if (response.httpInfo.success === false) { // broken url
results.broken.push({
id: bookmark.id,
title: bookmark.title,
url: bookmark.url,
duplicates: response.duplicateInfo.duplicates
broken: true
});
results.count++;
} else if (response.httpInfo.url !== bookmark.url) { // URL is different -> it changed and needs to be updated
results.changed.push({
id: bookmark.id,
title: bookmark.title,
url: bookmark.url,
newUrl: response.httpInfo.url,
additionalInfo: bookmark.additionalInfo
});
duplicateLabels.push(response.duplicateInfo.label);
results.count++;
}
}

if (response.httpInfo.success === false) { // broken url
results.broken.push({
id: bookmark.id,
title: bookmark.title,
url: bookmark.url,
broken: true
});
results.count++;
} else if (response.httpInfo.url !== bookmark.url) { // URL is different -> it changed and needs to be updated
results.changed.push({
id: bookmark.id,
title: bookmark.title,
url: bookmark.url,
newUrl: response.httpInfo.url,
additionalInfo: bookmark.additionalInfo
});
results.count++;
}
})["finally"](callback);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/js/helper/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
translationThanked: false,
performReopening: false,
entryAmounts: {},
linkcheckerIgnored: {},
lastOpened: null,
sort: {
name: "custom",
Expand Down
1 change: 1 addition & 0 deletions src/js/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
urlCheckLoading: "urlCheckLoading",
urlCheckCategories: "categories",
urlCheckAction: "urlCheckAction",
urlCheckHide: "urlCheckHide",
urlCheckResults: "urlCheckResults"
},
newtab: {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"default_locale": "en",
"version": "0.0.1",
"version_name": "Dev",
"minimum_chrome_version": "87",
"minimum_chrome_version": "89",
"homepage_url": "https://extensions.redeviation.com/",
"background": {
"scripts": [
Expand Down
7 changes: 5 additions & 2 deletions src/scss/dark/include/_linkchecker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ body.dark div.modal {
> ul > li {
border-bottom-color: $darkSeparatorColor;

a.urlCheckAction:hover {
background-color: $darkContentBackground2;
a.urlCheckAction, a.urlCheckHide {

&:hover {
background-color: $darkContentBackground2;
}
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions src/scss/include/_linkchecker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,18 @@ div.modal[data-type='checkBookmarks'] {
> strong, > a.info {
display: inline-block;
font-weight: $__fontWeightBold;
width: calc(100% - 94px);
width: calc(100% - 155px);
vertical-align: top;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

a.urlCheckAction {
@include mask('icon-delete', $__textColor, 18px);
a.urlCheckAction, a.urlCheckHide {
position: absolute;
top: 0;
bottom: 0;
margin: auto;
right: 10px;
display: block;
width: 32px;
height: 32px;
Expand All @@ -233,6 +231,16 @@ div.modal[data-type='checkBookmarks'] {
}
}

a.urlCheckAction {
@include mask('icon-delete', $__textColor, 18px);
right: 10px;
}

a.urlCheckHide {
@include mask('icon-hide', $__textColor, 18px);
right: 50px;
}

> ul.breadcrumb {
display: inline-block;
font-weight: $__fontWeightBold;
Expand Down Expand Up @@ -263,7 +271,7 @@ div.modal[data-type='checkBookmarks'] {
}

> ul[data-type='urls'] {
margin: 0 30px 0 65px;
margin: 0 90px 0 65px;

> li {
position: relative;
Expand Down Expand Up @@ -346,6 +354,13 @@ div.modal[data-type='checkBookmarks'] {
}
}
}

~ a.urlCheckHide {
@include mask('icon-hide', $__textColor, 18px);
right: 10px;
top: 12px;
bottom: unset;
}
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/scss/rtl/include/_linkchecker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ html[dir='rtl'] {
margin-right: 0;
}

a.urlCheckAction {
left: 10px;
right: unset;
}

a.urlCheckHide {
left: 50px;
right: unset;
}

> ul.breadcrumb {

> li:not(:last-child) {
Expand All @@ -89,7 +99,7 @@ html[dir='rtl'] {
}

> ul[data-type='urls'] {
margin-left: 30px;
margin-left: 90px;
margin-right: 65px;
}

Expand Down Expand Up @@ -120,11 +130,11 @@ html[dir='rtl'] {
}
}
}
}

a.urlCheckAction {
left: 10px;
right: unset;
~ a.urlCheckHide {
left: 10px;
right: unset;
}
}
}
}
Expand Down

0 comments on commit 09395e5

Please sign in to comment.