Differences From
Artifact [f01ba9ae01]:
34 34 })
35 35 }
36 36
37 37 /* div-based like and rt aren't very keyboard-friendly. add a replacement */
38 38 if (document.querySelector('body.timeline, body.profile, body.post') != null) {
39 39 onkey(window, function(event) {
40 40 if (focused()) {return;}
41 - let cururl = window._liveTweetMap.cur;
41 + let tmap = window._liveTweetMap;
42 + let cururl = tmap.cur;
42 43 let nexturl = null;
43 44 if (event.key == 'j') { // down
44 45 if (cururl == null) {
45 - nexturl = window._liveTweetMap.first
46 + nexturl = tmap.first;
46 47 } else {
47 - nexturl = window._liveTweetMap.map.get(cururl).next
48 + nexturl = tmap.map.get(cururl).next;
48 49 }
49 50 } else if (event.key == 'k') { // up
50 51 if (cururl == null) {
51 - nexturl = window._liveTweetMap.last
52 + nexturl = tmap.last;
52 53 } else {
53 - nexturl = window._liveTweetMap.map.get(cururl).prev
54 + nexturl = tmap.map.get(cururl).prev;
54 55 }
55 56 } else if (cururl != null) {
56 - let post = window._liveTweetMap.map.get(cururl).me
57 + let post = tmap.map.get(cururl).me;
58 + let root = tmap.map.get(cururl).go;
57 59 if (event.key == 'f') { // fave
58 - postReq(cururl, 'like', post.querySelector('.stats>.like'))
60 + postReq(root, 'like', post.querySelector('.stats>.like'))
59 61 } else if (event.key == 'r') { // rt
60 - postReq(cururl, 'rt', post.querySelector('.stats>.rt'))
61 - } else if (event.key == 'd') { // rt
62 - if (post.attributes.getNamedItem('data-own')) {
63 - window.location = cururl + '/del';
64 - }
62 + postReq(root, 'rt', post.querySelector('.stats>.rt'))
65 63 } else if (event.key == 'Enter') { // nav
66 - window.location = cururl;
64 + window.location = root;
67 65 return;
66 + } else if (post.attributes.getNamedItem('data-own')) {
67 + if (event.key == 'd') { window.location = root + '/del'; }
68 + else if (event.key == 'e') { window.location = root + '/edit'; }
69 + else if (event.key == 'u' && root != cururl) { window.location = cururl; } // detweet
68 70 }
69 71 }
70 72 if (nexturl != null) {
71 73 if (cururl != null) {
72 74 let cur = window._liveTweetMap.map.get(cururl);
73 75 cur.me.classList.remove('live-selected')
74 76 }
................................................................................
105 107 }
106 108 });
107 109 }
108 110
109 111 function attachButtons() {
110 112 let last = null;
111 113 let newmap = { cur: null, first: null, last: null, map: new Map() }
112 - document.querySelectorAll('main article.post').forEach(function(post){
113 - let url = posturl(post);
114 + document.querySelectorAll('main article.post:not([data-rt]), main div.lede').forEach(function(post){
115 + let ert = post.querySelector('article.post[data-rt]');
116 + let lede = null;
117 + if (ert != null) { lede = post; post = ert; }
118 + let purl = posturl(post);
119 + let url = null;
120 + if (lede == null) {url = purl;} else {
121 + url = lede.querySelector('a[href].del').
122 + attributes.getNamedItem('href').value;
123 + }
124 + console.log('post',post,'lede',lede,url);
125 +
114 126 if (last == null) { newmap.first = url; } else {
115 - newmap.map.get(last).next = url
127 + newmap.map.get(last).next = url;
116 128 }
117 - newmap.map.set(url, {me: post, prev: last, next: null})
118 - last = url
119 - if (window._liveTweetMap && window._liveTweetMap.cur == url) {
129 + newmap.map.set(url, {me: post, go: purl, prev: last, next: null})
130 + last = url;
131 + if (window._liveTweetMap &&
132 + window._liveTweetMap.cur == url
133 + ) {
120 134 post.classList.add('live-selected');
121 135 }
122 136
123 137 let stats = post.querySelector('.stats');
124 138 if (stats == null) {
125 139 /* no stats box; create one */
126 140 let n = mk('div');