/* * @title ShortNote autopagerize * @description 最新のノート (https://www.shortnote.jp/app/latest/) をautopagerize風 * @include https://www.shortnote.jp/app/latest/* * @license reblog commons license ( cc by 3.0 ) * @javascript_url */ (function() { var start_url = location.href; var State = true; var BASE_REMAIN_HEIGHT = 400; var BASE_URL = 'https://www.shortnote.jp/api/notes/list/'; var loading = false; var start = Number(start_url.replace(BASE_URL, '')); if (isNaN(start) || start == 0) start = 1; var next = start + 1; // next_page_load(); window.addEventListener('scroll', function() { if (loading) return; var remain = document.documentElement.scrollHeight - window.innerHeight - window.pageYOffset; if (State && remain < BASE_REMAIN_HEIGHT) { next_page_load(); } }, false); function next_page_load() { loading = true; var xhr = new XMLHttpRequest(); xhr.onload = function () { if (xhr.status <= 200 && xhr.status < 300) { var data = JSON.parse(xhr.responseText); var notes = data.notes; for (var i = 0,length = notes.length; i < length; i++) { document.querySelector('#view section.ng-scope div.latest-list.note-list-table.list-group').innerHTML += createNoteHtml(notes[i]); } loading = false; } else { error(); } }; xhr.open('GET', BASE_URL + next++, true); xhr.send(null); } function error(msg) { return console.log('error:' + msg); } function createNoteHtml(note) { var str = '