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

StealthLike Develop #1

Merged
merged 59 commits into from
Oct 16, 2013
Merged
Changes from 13 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0563298
ファイル追加
nezumi650 Aug 25, 2013
4a81a6e
いいねボタンを表示
nezumi650 Aug 25, 2013
38392b0
変数名が不適切だったので修正
nezumi650 Aug 25, 2013
943952f
いいねボタンを表示するURLを制限
nezumi650 Aug 25, 2013
96e4896
いいねボタンクリック時、選択範囲を取得
nezumi650 Aug 25, 2013
197c950
いいねボタン押下で、選択された範囲を引用してコメント
nezumi650 Aug 25, 2013
a708d3c
コメントの内容を修正
nezumi650 Aug 25, 2013
b957632
不要なところでjQuery使っていたので削除
nezumi650 Aug 27, 2013
e42cf38
ダブルクォートの必要がない箇所をシングルクォートに修正
nezumi650 Aug 27, 2013
bdbb1ac
変数の命名ルールを揃える
nezumi650 Aug 27, 2013
8d93cf3
分かりづらい変数名を修正
nezumi650 Aug 27, 2013
a9f4fee
ステルスコメントは表示しない
nezumi650 Aug 27, 2013
5fc5b21
ハイライトを実装してみたが、まだちゃんと動いてない
nezumi650 Aug 27, 2013
5c5470c
metadataを書く
nezumi650 Sep 3, 2013
848f035
全体を即時関数にする
nezumi650 Sep 3, 2013
0ff84f6
インデント修正
nezumi650 Sep 3, 2013
0529001
ハードタブが混ざっていたので、ソフトタブに変更
nezumi650 Sep 3, 2013
61996b8
use strict の記載位置を変更
nezumi650 Sep 4, 2013
d981028
作りきった感あるのでいったんコミット
nezumi650 Oct 1, 2013
07d11e0
いいねアイコンが最初の一個しかでていなかったので修正
nezumi650 Oct 1, 2013
d66ba9d
chrome で動作確認したら動かなかったので大々的に書き換え
nezumi650 Oct 2, 2013
b13f6f5
不要な処理を削除
nezumi650 Oct 2, 2013
d2cad5b
インデント修正
nezumi650 Oct 2, 2013
54323d3
location.pathname というものを教わったので修正
nezumi650 Oct 2, 2013
ccae545
README 設置
nezumi650 Oct 4, 2013
2ccde12
buttonElementMini へのdata属性付加方法修正
nezumi650 Oct 5, 2013
2a52632
buttonElementMini への class の付加方法修正
nezumi650 Oct 5, 2013
1fc762b
innerHTML を textContent に書き換え
nezumi650 Oct 5, 2013
c77dcc0
commentBody が取得できたかどうかの判定が厳密すぎたので緩和
nezumi650 Oct 5, 2013
9de8609
判定を厳密にする
nezumi650 Oct 5, 2013
c5f2a6c
過去にステルスライクされた事のないプルリクのコメントが全て隠れてしまうバグの修正
nezumi650 Oct 5, 2013
b25b841
ミニボタンからのステルスライク実装。
nezumi650 Oct 6, 2013
a50ecab
function文のおしりに ; 追加
nezumi650 Oct 6, 2013
e1cc26e
インデント修正
nezumi650 Oct 6, 2013
4d34221
element.remove() は得体の知れない関数だったので廃止
nezumi650 Oct 6, 2013
7693784
== undefind はあまり一般的じゃない様なので廃止
nezumi650 Oct 6, 2013
8eb02d9
Use strict equal operator === instead of ==
iizukak Oct 6, 2013
e487d26
Translate README into English
iizukak Oct 6, 2013
baefc3e
Merge remote-tracking branch 'origin/master' into first-dev
nezumi650 Oct 6, 2013
c0953b0
Merge pull request #7 from iizukak/translate-readme-ja-to-en
nezumi650 Oct 6, 2013
4eec6b1
コンフリクト解消
iizukak Oct 6, 2013
5efe976
マージ失敗して消してしまった差分を復活
iizukak Oct 6, 2013
39aefe2
Merge pull request #6 from iizukak/suggest-strict-equal-operator
nezumi650 Oct 6, 2013
c09e875
意味を分からず使っていた英文を削除
nezumi650 Oct 9, 2013
7198985
リファクタリング
nezumi650 Oct 9, 2013
669d6bf
関数式 を名前付きにする
nezumi650 Oct 9, 2013
e0a1fc1
querySelector内のシングルクォートをダブルクォートに変更
nezumi650 Oct 9, 2013
01d88d2
中間セーブ
nezumi650 Oct 9, 2013
6fe861d
名前付き関数式方式を関数宣言方式に戻す
nezumi650 Oct 15, 2013
80ae9c3
ミニいいねアイコン追加
nezumi650 Oct 15, 2013
ce3d9cc
ミニボタンは小さい画像を利用する
nezumi650 Oct 15, 2013
2299786
Merge remote-tracking branch 'origin/master' into first-dev
nezumi650 Oct 16, 2013
dc2c5c0
ミニボタン押下時の即時ハイライト
nezumi650 Oct 16, 2013
ee46278
不要に実行しまくっていた処理があったので修正
nezumi650 Oct 16, 2013
9974fdd
ステルスライクボタン押下時、即時ハイライト
nezumi650 Oct 16, 2013
5fac0e5
README 拡充
nezumi650 Oct 16, 2013
fd91d6d
微修正
nezumi650 Oct 16, 2013
6251b19
微修正
nezumi650 Oct 16, 2013
6ef5e52
微修正
nezumi650 Oct 16, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions stealthLike.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//'use strict';
Copy link

Choose a reason for hiding this comment

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

'use strict'; コメントしちゃ意味がないですよ。書くなら (function() { の下に書きましょう。

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed.


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();
}

}

Choose a reason for hiding this comment

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

関数式の場合は;をつけたほうがいいですねー。

こんなコード書いた時に見つけにくいバグを仕込んじゃうので。

var func = function(){
  alert(true);
}

(function(){
  // do something
})();

Copy link
Owner Author

Choose a reason for hiding this comment

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

function文(宣言?)の時は; 不要

function式の時は、後述の処理とひとつながりとして判断されてしまう事がある
このため、;が必要

Copy link
Owner Author

Choose a reason for hiding this comment

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

直します!

Copy link
Owner Author

Choose a reason for hiding this comment

The 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$/);
Copy link

Choose a reason for hiding this comment

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

ページで実行するしないは、metadata でかけます!

Copy link
Owner Author

Choose a reason for hiding this comment

The 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/*

Copy link
Owner Author

Choose a reason for hiding this comment

The 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();
});

})();