@@ -17,11 +17,14 @@ export default {
1717
1818 ( async ( ) => {
1919 try {
20+ // crawl emoji from https://emojipedia.org
21+ // Array.from(document.querySelectorAll('.emoji-list .emoji')).map(_ => _.textContent).join(',')
2022 let url = await UsefulScriptGlobalPageContext . Extension . getURL (
2123 "scripts/fb_moreReactionStory.json"
2224 ) ;
2325 const emojiJson = await fetch ( url ) ;
2426 const EMOJI_LIST = await emojiJson . json ( ) ;
27+
2528 loadModal ( EMOJI_LIST ) ;
2629 } catch ( e ) {
2730 console . error ( e ) ;
@@ -34,57 +37,96 @@ export default {
3437
3538 const timeoutCheckStoriesFooter = setInterval ( ( ) => {
3639 if ( ! window . location . href . includes ( "facebook.com/stories/" ) ) return ;
37- if ( ! ! document . querySelector ( ".btn-react" ) ) return ;
40+ if ( ! ! document . querySelector ( ".ufs-more-react-story" ) ) return ;
41+
42+ /* HTML template
43+ <div class="ufs-more-react-story">
44+ <button class="btn-react">More</button>
45+ <div class="emoji-container">
46+ <div class="emoji-tab-container">
47+ <div class="emoji-tab">😀</div>
48+ ...
49+ </div>
50+ <ul class="emoji-list-container">
51+ <li class="emoji">😀</li>
52+ ...
53+ </ul>
54+ </div>
55+ </div>
56+ */
57+
58+ const container = document . createElement ( "div" ) ;
59+ container . className = "ufs-more-react-story" ;
3860
3961 const btnReact = document . createElement ( "div" ) ;
4062 btnReact . textContent = "MORE" ;
41- btnReact . setAttribute ( "class" , "btn-react" ) ;
63+ btnReact . className = "btn-react" ;
64+ const emojiContainer = document . createElement ( "div" ) ;
65+ emojiContainer . className = "emoji-container" ;
66+ const emojiTabContener = document . createElement ( "div" ) ;
67+ emojiTabContener . className = "emoji-tab-container" ;
68+ const emojiListContainer = document . createElement ( "div" ) ;
69+ emojiListContainer . className = "emoji-list-container" ;
70+
71+ let allTabs = [ ] ;
72+ Object . keys ( EMOJI_LIST ) . map ( ( key ) => {
73+ const emojiTab = document . createElement ( "div" ) ;
74+ emojiTab . className = "emoji-tab" ;
75+ emojiTab . textContent = key ;
76+ allTabs . push ( emojiTab ) ;
77+
78+ emojiTab . onclick = ( ) => {
79+ allTabs . forEach ( ( tab ) => tab . classList . remove ( "active" ) ) ;
80+ emojiTab . classList . add ( "active" ) ;
81+ emojiListContainer . innerHTML = "" ;
82+
83+ const emojiList = EMOJI_LIST [ key ] . split ( "," ) ;
84+ emojiList . forEach ( ( emoji ) => {
85+ const emojiLi = document . createElement ( "li" ) ;
86+ emojiLi . className = "emoji" ;
87+ emojiLi . textContent = emoji ;
88+ emojiLi . setAttribute ( "value" , emoji ) ;
89+ emojiLi . onclick = async function ( ) {
90+ const storyId = getStoryId ( ) ;
91+ try {
92+ emojiLi . classList . add ( "loading" ) ;
93+ await reactStory ( user_id , fb_dtsg , storyId , emoji ) ;
94+ emojiLi . classList . remove ( "loading" ) ;
95+ addFloatingEmoji ( emoji , emojiLi ) ;
96+ } catch ( e ) {
97+ console . error ( e ) ;
98+ }
99+ } ;
100+
101+ emojiListContainer . appendChild ( emojiLi ) ;
102+ } ) ;
103+ } ;
42104
43- const emojiGroup = document . createElement ( "ul" ) ;
44- emojiGroup . setAttribute ( "class" , "emoji-group" ) ;
105+ emojiTabContener . appendChild ( emojiTab ) ;
106+ } ) ;
45107
46108 btnReact . onclick = function ( ) {
47- emojiGroup . classList . toggle ( "emoji-group-- show" ) ;
109+ emojiContainer . classList . toggle ( "show" ) ;
48110 } ;
49111
50- EMOJI_LIST . forEach ( ( emoji ) => {
51- const emojiLi = document . createElement ( "li" ) ;
52- emojiLi . setAttribute ( "class" , "emoji" ) ;
53- emojiLi . setAttribute ( "value" , emoji . value ) ;
54- emojiLi . textContent = emoji . value ;
55- emojiLi . onclick = async function ( ) {
56- const storyId = getStoryId ( ) ;
57- try {
58- emojiLi . classList . add ( "loading" ) ;
59- await reactStory ( user_id , fb_dtsg , storyId , emoji . value ) ;
60- emojiLi . classList . remove ( "loading" ) ;
61- addFloatingEmoji ( emoji , emojiLi ) ;
62- } catch ( e ) {
63- console . error ( e ) ;
64- }
65- } ;
66-
67- emojiGroup . appendChild ( emojiLi ) ;
68- } ) ;
69-
70- const reactContainer = document . createElement ( "div" ) ;
71- reactContainer . setAttribute ( "class" , "react-container" ) ;
72- reactContainer . appendChild ( btnReact ) ;
73- reactContainer . appendChild ( emojiGroup ) ;
112+ emojiContainer . appendChild ( emojiTabContener ) ;
113+ emojiContainer . appendChild ( emojiListContainer ) ;
114+ container . appendChild ( btnReact ) ;
115+ container . appendChild ( emojiContainer ) ;
74116
75117 const storiesFooter = document . getElementsByClassName (
76118 "x11lhmoz x78zum5 x1q0g3np xsdox4t x10l6tqk xtzzx4i xwa60dl xl56j7k xtuxyv6"
77119 ) ;
78120 if ( storiesFooter . length > 0 ) {
79121 // clearInterval(timeoutCheckStoriesFooter);
80- storiesFooter [ storiesFooter . length - 1 ] . appendChild ( reactContainer ) ;
122+ storiesFooter [ storiesFooter . length - 1 ] . appendChild ( container ) ;
81123 }
82124 } , 1e3 ) ;
83125 }
84126 function addFloatingEmoji ( emoji , ele ) {
85127 let floatingEmoji = document . createElement ( "div" ) ;
86128 floatingEmoji . setAttribute ( "class" , "floating-emoji" ) ;
87- floatingEmoji . textContent = emoji . value ;
129+ floatingEmoji . textContent = emoji ;
88130
89131 let { top, left } = ele . getBoundingClientRect ( ) ;
90132 floatingEmoji . style . position = "fixed" ;
0 commit comments