(function(){'use strict';const a='yy_add_to_home',b='yy_add_to_home_queue',c='yy_add_to_home_context_menu',d='yy_global_search',e='yy-global-search-script',f={'origins':['http://*/*','https://*/*']},g='yy_global_cursor',h='yy-global-cursor-script';function i(){chrome['storage']['local']['get'](c,r=>{const s=r[c]!==![];if(!chrome?.['contextMenus'])return;chrome['contextMenus']['removeAll'](()=>{s&&chrome['contextMenus']['create']({'id':a,'title':'添加至主页','contexts':['page','link'],'documentUrlPatterns':['http://*/*','https://*/*']});});});}function j(){if(!chrome?.['scripting'])return;chrome['scripting']['registerContentScripts']([{'id':e,'matches':['http://*/*','https://*/*'],'js':['i18n-loader.js','content_scripts/search.js'],'runAt':'document_end'}],()=>{chrome['runtime']['lastError']&&(!chrome['runtime']['lastError']['message']?.['includes']('already\x20registered')&&console['warn']('Register\x20search\x20script\x20error:',chrome['runtime']['lastError']['message']));});}function k(){if(!chrome?.['scripting'])return;chrome['scripting']['unregisterContentScripts']({'ids':[e]},()=>{if(chrome['runtime']['lastError']){}});}function l(){if(!chrome?.['scripting'])return;chrome['scripting']['registerContentScripts']([{'id':h,'matches':['http://*/*','https://*/*'],'js':['content_scripts/cursor.js'],'runAt':'document_start','allFrames':!![]}],()=>{chrome['runtime']['lastError']&&(!chrome['runtime']['lastError']['message']?.['includes']('already\x20registered')&&console['warn']('Register\x20cursor\x20script\x20error:',chrome['runtime']['lastError']['message']));});}function m(){if(!chrome?.['scripting'])return;chrome['scripting']['unregisterContentScripts']({'ids':[h]},()=>{if(chrome['runtime']['lastError']){}});}function n(){chrome['storage']['local']['get'](d,r=>{const s=r[d]===!![];if(!s){k();return;}chrome['permissions']['contains'](f,t=>{t?j():k();});});}function o(){chrome['storage']['local']['get'](g,r=>{const s=r[g]===!![];console['log']('[Cursor]\x20syncCursorScript\x20called,\x20isEnabled:',s);if(!s){m();return;}chrome['permissions']['contains'](f,t=>{console['log']('[Cursor]\x20permission\x20allowed:',t),t?l():console['log']('[Cursor]\x20waiting\x20for\x20permission...');});});}async function p(r){try{const s=await fetch(r),t=await s['text']();return{'success':!![],'data':t};}catch(u){return{'success':![],'error':u['message']};}}async function q(r){try{const s='https://go.aiyyx.com/api/tencent_fy',t=new URLSearchParams();t['append']('SourceText',r['SourceText']||''),t['append']('Target',r['Target']||'en');const u=await fetch(s+'?'+t['toString']()),v=await u['json']();return{'success':!![],'data':v};}catch(w){return{'success':![],'error':w['message']};}}chrome['runtime']['onMessage']['addListener']((r,s,t)=>{if(r['type']==='YY_FETCH_SUGGEST'&&r['url'])return p(r['url'])['then'](t),!![];if(r['type']==='YY_FETCH_TRANSLATE'&&r['data'])return q(r['data'])['then'](t),!![];}),chrome['contextMenus']['onClicked']['addListener']((r,s)=>{if(r['menuItemId']!==a||!s?.['id'])return;const t=r['linkUrl']||r['pageUrl'],u=r['linkText']||s['title']||'';if(!t)return;const v={'id':Date['now']()['toString'](),'name':u,'url':t,'type':'icon','timestamp':Date['now']()};chrome['storage']['local']['get'](b,w=>{const x=w[b]||[];x['push'](v),chrome['storage']['local']['set']({[b]:x},()=>{chrome['tabs']['query']({'url':'chrome://newtab/'},y=>{y['forEach'](z=>{z['id']&&chrome['tabs']['sendMessage'](z['id'],{'type':'YY_ADD_TO_HOME','data':v});});});});});}),chrome['storage']['onChanged']['addListener'](r=>{const s=[c,d,g];if(!s['some'](t=>r[t]))return;console['log']('storage\x20changed',r),r[c]&&i(),r[d]&&n(),r[g]&&o();}),chrome['permissions']['onAdded']['addListener'](()=>{n(),o();}),chrome['permissions']['onRemoved']['addListener'](()=>{n(),o();}),chrome['runtime']['onInstalled']['addListener'](()=>{i(),n(),o();}),chrome['runtime']['onStartup']['addListener'](()=>{i(),n(),o();});}());