| | 99 | function getCurrentListBox(){ |
| | 100 | return tabBox.tabpanels.selectedPanel.firstChild; |
| | 101 | } |
| | 102 | function getParent(node, class){ |
| | 103 | let elm = node; |
| | 104 | while (elm != document.documentElement){ |
| | 105 | if (elm instanceof class) |
| | 106 | return elm; |
| | 107 | elm = elm.parentNode; |
| | 108 | } |
| | 109 | return null; |
| | 110 | } |
| | 111 | var gActions = (function(){ |
| | 112 | function getItemIndex(listbox, arg){ |
| | 113 | let index = 0, currentIndex = listbox.selectedIndex; |
| | 114 | switch (arg) { |
| | 115 | case "0": |
| | 116 | return 0; |
| | 117 | case "$": |
| | 118 | return listbox.itemCount - 1; |
| | 119 | case "+1": |
| | 120 | if (currentIndex == listbox.itemCount - 1) |
| | 121 | return null; |
| | 122 | return currentIndex + 1; |
| | 123 | case "-1": |
| | 124 | if (currentIndex == -1) |
| | 125 | return null; |
| | 126 | return currentIndex - 1; |
| | 127 | default: |
| | 128 | return null; |
| | 129 | } |
| | 130 | } |
| | 131 | function getCopyItem(target){ |
| | 132 | let listbox = getCurrentListBox(); |
| | 133 | let item = listbox.selectedItem; |
| | 134 | if (!item) |
| | 135 | return null; |
| | 136 | switch (target){ |
| | 137 | case "ID": |
| | 138 | return item.value; |
| | 139 | case "SCREENNAME": |
| | 140 | return item.querySelector(".twlist-screenname").textContent; |
| | 141 | case "TEXT": |
| | 142 | return item.querySelector(".twlist-text").textContent; |
| | 143 | case "SELECTION": |
| | 144 | return window.getSelection().toString(); |
| | 145 | case "URL": |
| | 146 | let node = document.popupNode; |
| | 147 | if (node) { |
| | 148 | let elm = getParent(node, HTMLAnchorElement); |
| | 149 | if (elm) |
| | 150 | return elm.getAttribute("href"); |
| | 151 | } |
| | 152 | } |
| | 153 | return null; |
| | 154 | } |
| | 155 | var self = { |
| | 156 | copy: function(target){ |
| | 157 | let text = getCopyItem(target); |
| | 158 | if (text) { |
| | 159 | liberator.modules.util.copyToClipboard(text, true); |
| | 160 | } |
| | 161 | }, |
| | 162 | select: function(arg){ |
| | 163 | let listbox = getCurrentListBox(); |
| | 164 | let index = getItemIndex(listbox, arg); |
| | 165 | listbox.ensureIndexIsVisible( listbox.selectedIndex = index ); |
| | 166 | }, |
| | 167 | reply: function(){ |
| | 168 | let listbox = getCurrentListBox(); |
| | 169 | let item = listbox.selectedItem; |
| | 170 | if (!item) |
| | 171 | return; |
| | 172 | twlist.onReply(item.querySelector(".twlist-reply"), (listbox == dmBox)); |
| | 173 | }, |
| | 174 | retweet: function(){ |
| | 175 | let listbox = getCurrentListBox(); |
| | 176 | if (listbox == dmBox) |
| | 177 | return; |
| | 178 | let item = listbox.selectedItem; |
| | 179 | if (!item) |
| | 180 | return; |
| | 181 | twlist.onRetweet(item.querySelector(".twlist-retweet")); |
| | 182 | }, |
| | 183 | fav: function(){ |
| | 184 | let listbox = getCurrentListBox(); |
| | 185 | if (listbox == dmBox) |
| | 186 | return; |
| | 187 | let item = listbox.selectedItem; |
| | 188 | if (!item) |
| | 189 | return; |
| | 190 | twlist.onFav(item.querySelector(".twlist-fav")); |
| | 191 | } |
| | 192 | }; |
| | 193 | return self; |
| | 194 | })(); |
| | 195 | var gContext = (function(){ |
| | 196 | var popupNode = null, anchor; |
| | 197 | function showItem (item, show, text){ |
| | 198 | if (show){ |
| | 199 | if (item.hasAttribute("hidden")) |
| | 200 | item.removeAttribute("hidden"); |
| | 201 | if (text) |
| | 202 | item.setAttribute("tooltiptext", text); |
| | 203 | } else { |
| | 204 | item.setAttribute("hidden", true); |
| | 205 | if (item.hasAttribute("tooltiptext")) |
| | 206 | item.removeAttribute("tooltiptext"); |
| | 207 | } |
| | 208 | } |
| | 209 | function getSelText(text){ |
| | 210 | if (text.length > 20) |
| | 211 | return text.substr(20) + "..."; |
| | 212 | return text; |
| | 213 | } |
| | 214 | var self = { |
| | 215 | showing: function gContextShowing(){ |
| | 216 | let listbox = getCurrentListBox(); |
| | 217 | if (!listbox.selectedItem) |
| | 218 | return false; |
| | 219 | popupNode = document.popupNode; |
| | 220 | let openLinkMenu = $("twlist-menuitem-openlink"), |
| | 221 | openLinkTabMenu = $("twlist-menuitem-openlinktab"), |
| | 222 | copyURLMenu = $("twlist-menuitem-copy-url"), |
| | 223 | isAnchor = false, |
| | 224 | href = null; |
| | 225 | anchor = getParent(popupNode, HTMLAnchorElement); |
| | 226 | if (anchor){ |
| | 227 | isAnchor = true; |
| | 228 | href = anchor.getAttribute("href"); |
| | 229 | } |
| | 230 | showItem(openLinkMenu, isAnchor, href); |
| | 231 | showItem(openLinkTabMenu, isAnchor, href); |
| | 232 | showItem(copyURLMenu, isAnchor, href); |
| | 233 | let sel = window.getSelection(), |
| | 234 | selectMenu = $("twlist-menuitem-copy-selection"); |
| | 235 | showItem(selectMenu, (sel.toString() != ""), getSelText(sel.toString())); |
| | 236 | return true; |
| | 237 | }, |
| | 238 | hiding: function gContextHiding(){ |
| | 239 | anchor = null; |
| | 240 | }, |
| | 241 | openLink: function(newTab) { |
| | 242 | if (popupNode instanceof HTMLAnchorElement) { |
| | 243 | liberator.open(popupNode.getAttribute("href"), |
| | 244 | {where: (newTab ? liberator.NEW_TAB : liberator.CURRENT_TAB) }); |
| | 245 | } |
| | 246 | } |
| | 247 | }; |
| | 248 | return self; |
| | 249 | })(); |
| | 251 | <commandset id="twlist-commandset"> |
| | 252 | <command id="cmd_select_next" oncommand="gActions.select('+1')"/> |
| | 253 | <command id="cmd_select_prev" oncommand="gActions.select('-1')"/> |
| | 254 | <command id="cmd_select_first" oncommand="gActions.select('0')"/> |
| | 255 | <command id="cmd_select_last" oncommand="gActions.select('$')"/> |
| | 256 | <command id="cmd_reply" oncommand="gActions.reply()"/> |
| | 257 | <command id="cmd_retweet" oncommand="gActions.retweet()"/> |
| | 258 | <command id="cmd_fav" oncommand="gActions.fav()"/> |
| | 259 | </commandset> |
| | 260 | <keyset id="twlist-keyset"> |
| | 261 | <key id="key_select_next" command="cmd_select_next" key="J"/> |
| | 262 | <key id="key_select_prev" command="cmd_select_prev" key="K"/> |
| | 263 | <key id="key_select_first" command="cmd_select_first" key="G"/> |
| | 264 | <key id="key_select_last" command="cmd_select_last" key="G" modifiers="shift"/> |
| | 265 | <key id="key_reply" command="cmd_reply" key="R"/> |
| | 266 | <key id="key_retweet" command="cmd_retweet" key="R" modifiers="shift"/> |
| | 267 | <key id="key_fav" command="cmd_fav" key="F"/> |
| | 268 | </keyset> |
| | 269 | <popupset> |
| | 270 | <popup id="twlist-context" |
| | 271 | onpopupshowing="if(event.target!=this) return true; return gContext.showing();" |
| | 272 | onpopuphiding="if(event.target==this){gContext.hiding();}"> |
| | 273 | <menuitem id="twlist-menuitem-openlink" label="Open" oncommand="gContext.openLink()"/> |
| | 274 | <menuitem id="twlist-menuitem-openlinktab" label="Open in a new tab" oncommand="gContext.openLink(true)"/> |
| | 275 | <menu id="twlist-menu-copy" label="Copy" accesskey="C"> |
| | 276 | <menupopup> |
| | 277 | <menuitem id="twlist-menuitem-copy-text" label="Text" accesskey="T" oncommand="gActions.copy('TEXT')"/> |
| | 278 | <menuitem id="twlist-menuitem-copy-id" label="ID" accesskey="I" oncommand="gActions.copy('ID')"/> |
| | 279 | <menuitem id="twlist-menuitem-copy-name" label="ScreenName" accesskey="S" oncommand="gActions.copy('SCREENNAME')"/> |
| | 280 | <menuitem id="twlist-menuitem-copy-selection" label="Copy Selection" oncommand="gActions.copy('SELECTION')"/> |
| | 281 | <menuitem id="twlist-menuitem-copy-url" label="URL" accesskey="U" oncommand="gActions.copy('URL')"/> |
| | 282 | </menupopup> |
| | 283 | </menu> |
| | 284 | <menuitem id="twlist-menuitem-rt" label="RT" accesskey="T" oncommand="gActions.retweet()"/> |
| | 285 | <menuitem id="twlist-menuitem-reply" label="Reply" accesskey="R" oncommand="gActions.reply()"/> |
| | 286 | <menuitem id="twlist-menuitem-fav" label="Fav" accesskey="F" oncommand="gActions.fav()"/> |
| | 287 | </popup> |
| | 288 | </popupset> |