無限スクロールとか
jkキーでフォーカス移動とか
できない?
一画面目から落ちちゃうとと反応が悪くなるので、どうにかしたい。
以下は追記です:
jkキーでフォーカス移動
まずはここまでできた。F12押してペタると、jを押すと次のアイテムがトップにくる。最後のアイテムだとエラーがでると思う。
javascript
1! function() { 2 window.addEventListener("keydown", function(e) { 3 if ((["a", "input", "select", "textarea", "button"] 4 .indexOf((document.activeElement || window.getSelection().focusNode).nodeName.toLowerCase()) == -1)) { 5 dir = e.which == 74 ? +1 : e.which == 75 ? -1 : 0 6 if(dir!=0) { 7 bi = document.getElementsByClassName("boxItem") 8 f = document.getElementsByClassName("focus")[0] 9 if (f) f.classList.remove("focus") 10 f = bi[Array.prototype.slice.call(bi).indexOf(f) + dir] 11 f.classList.add("focus") 12 document.body.scrollTop += -45 + f.getBoundingClientRect().top 13 } 14 } 15 }) 16}()
残課題:
- 別タブに boxItem があるとそっちにフォーカスが行ってしまう。 parentElement.parentElement.style.display で区別できそう。
無限スクロール
まずはここまでできた。F12押してペタると表示しているタブが無限スクロールになる。
javascript
1(function(a) { 2 window.addEventListener("scroll", function() { 3 for (var i = 0; i < a.length; i++){ 4 if(a[i].parentElement.style.display != "none" 5 && a[i].getBoundingClientRect().top < 500) { 6 e = document.createEvent("MouseEvents"); 7 e.initMouseEvent("click", true, true); 8 a[i].dispatchEvent(e); 9 } 10 } 11 }) 12}(document.getElementsByClassName('boxShowMore')))
残課題:
- 500 適当に自分の画面の縦サイズに合わせてる。残りスクロール量とか下からの位置を取るやり方がよくわからない。
- scrollイベントで大量にdispatchEventを発火しちゃってるはずのでよくない。気にしないことにしよう。
bookmarklet版: (使い方: このページをブックマークして、ブックマークの編集画面で、名前を「Teratail無限スクロール」、URLを下の文字列に置き換える。で、Teratailのトップ画面を表示したら、そのブックマークを選ぶ。と、スクロールダウンすると自動的に次を読み込むようになります)
javascript:(function(a) {window.addEventListener("scroll", function() {for (var i = 0; i < a.length; i++){ if(a[i].parentElement.style.display != "none" && a[i].getBoundingClientRect().top < 500) { e = document.createEvent("MouseEvents"); e.initMouseEvent("click", true, true); a[i].dispatchEvent(e); }}})}(document.getElementsByClassName('boxShowMore')))
残課題:
- teratailに取り込んでもらいたい。取り込んでもらいたい。取り込んでもらいたい。
「もっと見る」の件数を増やす、ページをスキップする
- 件数を増やすには
javascript:limit=20
とかやる。 - ページ番号をスキップするには、「もっと見る」ボタンを一回押したあと、「もっと見る」ボタン要素の直前にある .feed_reload/text() の数字を増やすか、
javascript:document.getElementsByClassName("feed_reload")[0].innerText+=100
とかやる。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/28 23:02