Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Add: utilizing local meta keywords tags to suggest better and more relevant tags #47

Merged
merged 5 commits into from Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/manifest.json
Expand Up @@ -29,7 +29,7 @@
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"run_at": "document_start",
"js": ["scripts/description.js"],
"js": ["scripts/description.js", "scripts/keywords_suggestions.js"],
"all_frames": true
}],
"icons": {
Expand Down
8 changes: 7 additions & 1 deletion app/scripts/background.js
Expand Up @@ -237,7 +237,7 @@ var deletePost = function (url) {
}
};

var getSuggest = function (url) {
var getSuggest = function (url, keywordTags) {
if (Pinboard.isLoggedin() && url) {
var doneFn = function (data) {
var popularTags = [], recommendedTags = [];
Expand All @@ -252,6 +252,12 @@ var getSuggest = function (url) {
suggests.push(tag);
}
});

if (keywordTags !== undefined && keywordTags.length !== 0) {
suggests = suggests.concat(keywordTags);
suggests = suggests.sort().filter(function(item, pos, ary) {return !pos || item != ary[pos - 1];});
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to replace the tabs in this block into 2 spaces? It'd be identical with the full project.
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set and pushed.

var popup = getPopup();
popup && popup.$rootScope &&
popup.$rootScope.$broadcast('render-suggests', suggests);
Expand Down
13 changes: 13 additions & 0 deletions app/scripts/keywords_suggestions.js
@@ -0,0 +1,13 @@
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
if (message.method == "getKeywordsSuggestionTags") {
var metas = document.getElementsByTagName('meta');
for (i=0; i < metas.length; i++) {
if (metas[i].getAttribute("name") === "keywords") {
var tags = metas[i].getAttribute("content").toLowerCase().replace(/,/g, ' ').replace(/;/, '').split(/(\s+)/).filter(function(e) { return e.trim().length > 0; }).sort().filter(function(item, pos, ary) {return !pos || item != ary[pos - 1];});
break
}
}
sendResponse({data: tags});
}
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to replace the tabs into 2 spaces? It'd be identical with the full project.
Thanks!

21 changes: 20 additions & 1 deletion app/scripts/popup.js
Expand Up @@ -74,6 +74,24 @@ app.controller(
});
};

var getKeywordsSuggestionTags = function () {
chrome.tabs.query(
{active:true, currentWindow: true}, function (activetabs) {
var tab = activetabs[0];
chrome.tabs.sendMessage(
tab.id, {method: 'getKeywordsSuggestionTags'},
function (response) {
if (typeof response !== 'undefined') {
var tags = response.data;
bg.getSuggest(tab.url, tags);
}
else {
bg.getSuggest(tab.url);
}
});
});
};

var initAutoComplete = function () {
var tags = bg.getTags();
if (tags && tags.length) {
Expand Down Expand Up @@ -105,7 +123,8 @@ app.controller(
$scope.isLoading = false;
$scope.isAnony = false;
$scope.$apply();
bg.getSuggest(tab.url);
//bg.getSuggest(tab.url);
getKeywordsSuggestionTags();
initAutoComplete();
if (location.search != '?focusHack') {
location.search = '?focusHack';
Expand Down