-
Notifications
You must be signed in to change notification settings - Fork 3
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
StealthLike Develop #1
Changes from 13 commits
0563298
4a81a6e
38392b0
943952f
96e4896
197c950
a708d3c
b957632
e42cf38
bdbb1ac
8d93cf3
a9f4fee
5fc5b21
5c5470c
848f035
0ff84f6
0529001
61996b8
d981028
07d11e0
d66ba9d
b13f6f5
d2cad5b
54323d3
ccae545
2ccde12
2a52632
1fc762b
c77dcc0
9de8609
c5f2a6c
b25b841
a50ecab
e1cc26e
4d34221
7693784
8eb02d9
e487d26
baefc3e
c0953b0
4eec6b1
5efe976
39aefe2
c09e875
7198985
669d6bf
e0a1fc1
01d88d2
6fe861d
80ae9c3
ce3d9cc
2299786
dc2c5c0
ee46278
9974fdd
5fac0e5
fd91d6d
6251b19
6ef5e52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//'use strict'; | ||
|
||
var defaultComment = 'Stealth Liked'; | ||
|
||
// add a stealth-like-button | ||
var buttonElement = document.createElement('img'); | ||
buttonElement.id = 'stealth-like-button'; | ||
buttonElement.src = 'https://raw.github.com/nezumi650/StealthLike/master/sample.png'; | ||
buttonElement.width = 50; | ||
buttonElement.height = 50; | ||
buttonElement.style.cssText = 'position: fixed;' | ||
+ 'bottom: 20px;' | ||
+ 'right: 20px;'; | ||
|
||
var footerElement = document.querySelector('div .site-footer'); | ||
footerElement.appendChild(buttonElement); | ||
|
||
|
||
// post comment with selected text | ||
function postLikeComment(comment) { | ||
var commentForm = document.querySelector( '#discussion_bucket .js-new-comment-form [id^=\'comment_body_\']' ); | ||
commentForm.value = defaultComment + ' :+1:' + "\n" + ' > ' + comment; | ||
|
||
var submitButton = document.querySelector('#discussion_bucket .js-new-comment-form button[type=\'submit\']:last-child'); | ||
var mouseEvents = document.createEvent('MouseEvents'); | ||
mouseEvents.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | ||
submitButton.dispatchEvent( mouseEvents ); | ||
} | ||
|
||
function hideStealthComments() { | ||
var discussionBubbles = document.querySelectorAll('.discussion-bubble'); | ||
var targetTextsArray = []; | ||
|
||
for (var i = 0; i < discussionBubbles.length; i++) { | ||
var discussionBubble = discussionBubbles[i]; | ||
var commentBody = discussionBubble.querySelector('.comment-body'); | ||
|
||
if (commentBody != null) { | ||
var commentBodyText = commentBody.textContent; | ||
if (commentBodyText.search(defaultComment) != -1) { | ||
var blockquoteBody = discussionBubble.querySelector('blockquote p'); | ||
if (blockquoteBody != null) { | ||
targetTextsArray.push(blockquoteBody.innerHTML); | ||
} | ||
discussionBubble.style.display = 'none'; | ||
discussionBubble.remove(); | ||
} | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 関数式の場合は こんなコード書いた時に見つけにくいバグを仕込んじゃうので。 var func = function(){
alert(true);
}
(function(){
// do something
})(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function文(宣言?)の時は function式の時は、後述の処理とひとつながりとして判断されてしまう事がある There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 直します! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
} | ||
|
||
// hilightStealthComments(targetTextsArray); | ||
} | ||
|
||
function hilightStealthComment(targetHtml, targetText) { | ||
return targetHtml.replace(targetText, '<span style=\'background-color:yellow\' >' + targetText + '</span>'); | ||
} | ||
|
||
function hilightStealthComments(targetTextArray) { | ||
var jsDiscussionElement = document.querySelector('.js-discussion'); | ||
var targetHtml = jsDiscussionElement.innerHTML; | ||
var replacedHtml = ''; | ||
|
||
for (var i = 0; i < targetTextArray.length; i++) { | ||
var targetText = targetTextArray[i]; | ||
replacedHtml = hilightStealthComment(targetHtml, targetText); | ||
targetHtml = replacedHtml; | ||
} | ||
document.querySelector('.js-discussion').innerHTML = replacedHtml; | ||
} | ||
|
||
|
||
|
||
|
||
(function() { | ||
var stealthLikeButton = $('#stealth-like-button'); | ||
stealthLikeButton.hide(); | ||
|
||
// 少しでもスクロールしたら表示 | ||
$(window).scroll(function () { | ||
var currentUrl = location.href; | ||
var isGithub = currentUrl.match(/github\.com.*pull/); | ||
var isCommitsPage = currentUrl.match(/commits$/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ページで実行するしないは、metadata でかけます! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. metadata にこんな風に書いてみたのですが、うまく動作制御する事ができなかったので、 // @exclude https://github.com/*/pull/*/commits
// @include https://github.com/*/pull/*/files
// @include https://github.com/*/pull/* There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
if (isGithub && !isCommitsPage) { | ||
if ($(this).scrollTop() > 1) { | ||
stealthLikeButton.fadeIn(); | ||
} else { | ||
stealthLikeButton.fadeOut(); | ||
} | ||
} | ||
}); | ||
|
||
stealthLikeButton.click(function () { | ||
postLikeComment(window.getSelection()); | ||
return false; | ||
}); | ||
|
||
// 非推奨.. | ||
var targetElement = document.querySelector('.js-task-list-container'); | ||
targetElement.addEventListener("DOMNodeInserted", function () { | ||
hideStealthComments(); | ||
}); | ||
|
||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'use strict';
コメントしちゃ意味がないですよ。書くなら(function() {
の下に書きましょう。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.