-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-star-note.user.js
More file actions
117 lines (110 loc) · 4.24 KB
/
github-star-note.user.js
File metadata and controls
117 lines (110 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ==UserScript==
// @name Github Star Note
// @description star note of the repository on Github.
// @namespace satoshi honda
// @include https://github.com/stars*
// @include https://github.com/*/*
// @author satoshi honda <bin.honda@gmail.com>
// @namespace http://userscripts.org/scripts/show/158337
// @version 0.0.2
// ==/UserScript==
(function (d, func) {
var h = d.getElementsByTagName('head')[0];
var s1 = d.createElement("script");
s1.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
s1.addEventListener('load', function() {
var s2 = d.createElement("script");
s2.textContent = "jQuery.noConflict();(" + func.toString() + ")(jQuery);";
h.appendChild(s2);
}, false);
h.appendChild(s1);
})(document, function($) {
var href = window.location.href;
var pathname = window.location.pathname;
var showStarNote = function() {
$("div.search").prepend(
' <p>'
+ ' <input type="text" name="star_note_search" id="star-note-search" value="" class="filter_input" placeholder="Search starred notes.." autocapitalize="off" autocomplete="off" data-hotkey="/" tabindex="2" data-url="/stars/search">'
+ '</p>'
);
$("ul.repo_list li").each(function() {
repo_full_name = $("a.js-navigation-open", this).text();
if(localStorage.hasOwnProperty("github_star_note")) {
var item = JSON.parse(localStorage.getItem("github_star_note"));
if(item.hasOwnProperty(repo_full_name)) {
$(this).append('<p class="description"><strong>' + item[repo_full_name] + '</strong></p>');
}
}
});
$("#star-note-search").keypress(function(e) {
if (e.which == 13) {
$(".repo_list").remove();
showStarNoteSearch();
}
});
}
var editStarNote = function() {
var repo_full_name = pathname.replace("/", "");
$("a.unstarred").click(function() {
if($("#star-note").length == 0) {
$(".title-actions-bar").append(
'<div style="text-align:right;" class="star-note">'
+ '<input type="text" name="star_note" style="width:400px" value="" placeholder="Add a stars note to this repository"/>'
+ '<span class="minibutton" id="star-note"><span class="js-select-button">Star Note</span></span>'
+ '</div>'
);
}
$("span#star-note").click(function() {
var item = {};
if(localStorage.hasOwnProperty("github_star_note")) {
item = JSON.parse(localStorage.getItem("github_star_note"));
}
item[repo_full_name] = $('input[name="star_note"]').val();
localStorage.setItem("github_star_note", JSON.stringify(item));
$(".star-note").remove();
});
});
$("a.starred").click(function() {
if(localStorage.hasOwnProperty("github_star_note")) {
var item = JSON.parse(localStorage.getItem("github_star_note"));
if(item.hasOwnProperty(repo_full_name)) {
delete(item[repo_full_name]);
localStorage.setItem("github_star_note", JSON.stringify(item));
}
}
});
}
var showStarNoteSearch = function() {
if(localStorage.hasOwnProperty("github_star_note")) {
var item = JSON.parse(localStorage.getItem("github_star_note"));
$.each(item, function(k, v) {
var search_val = $('input[name="star_note_search"]').val();
reg = new RegExp(search_val);
if (v.match(reg)) {
$("div.js-navigation-container").append(
'<ul class="repo_list" id="js-repo-list">'
+ ' <li class="starred-repo public source js-navigation-item navigation-focus">'
+ ' <span class="mega-icon mega-icon-public-repo"></span>'
+ ' <h3><a href="/' + k + '" class="js-navigation-open">' + k + '</a></h3>'
+ ' <p class="description">' + v + '</p>'
+ ' </li>'
+ '</ul>'
);
}
});
}
}
var isStarsUrl = function() {
return href.match(/stars/) ? true : false;
}
var isStarsSearch = function() {
return href.match(/q=/) ? true : false;
}
$(document).ready(function(){
if (isStarsUrl()) {
showStarNote();
} else {
editStarNote();
}
});
});