Chrome Gemini Nano

Chrome内置Gemini Nano大模型尝鲜

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Chrome Gemini Nano 
// @namespace    http://tampermonkey.net/
// @version      2024-06-11
// @description  Chrome内置Gemini Nano大模型尝鲜
// @author       shiyi
// @match        *://*/*
// @icon         data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjYzIiB2aWV3Qm94PSIwIDAgNjMgNjMiIHdpZHRoPSI2MyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PGxpbmVhckdyYWRpZW50IGlkPSJhIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjM0LjkwODciIHgyPSI3LjYzMjI0IiB5MT0iNjEuMDI5IiB5Mj0iMTMuNzg0NyI+PHN0b3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DY4NyA1LjU4MjUtMTIuNDY4NyAxMi40Njg4IDUuNTgyNCAxMi40Njg4IDEyLjQ2ODcgMTIuNDY4OHoiIGZpbGw9IiMxYTczZTgiLz48cGF0aCBkPSJtMzEuNDk5MSAxNS43NWgyNy4yNzU0Yy0yLjc2NC00Ljc4ODgtNi43NC04Ljc2NTUzLTExLjUyODMtMTEuNTMwMjktNC43ODgzLTIuNzY0NzUtMTAuMjIwMi00LjIyMDEwMjM1LTE1Ljc0OTQtNC4yMTk3MDk5MnMtMTAuOTYwOCAxLjQ1NjUwOTkyLTE1Ljc0ODcgNC4yMjE5NDk5MmMtNC43ODggMi43NjU0My04Ljc2MzQxIDYuNzQyNzUtMTEuNTI2NjYgMTEuNTMxODVsMTMuNjM3NjYgMjMuNjIxMi4wMDM1LjAwMTljLTEuMzgzNy0yLjM5NC0yLjExMjctNS4xMS0yLjExMzYtNy44NzUxcy43MjY0LTUuNDgxNyAyLjEwODYtNy44NzY1YzEuMzgyMS0yLjM5NDggMy4zNzA2LTQuMzgzNSA1Ljc2NTItNS43NjU5IDIuMzk0Ny0xLjM4MjUgNS4xMTEyLTIuMTEgNy44NzYzLTIuMTA5NHoiIGZpbGw9InVybCgjYykiLz48L3N2Zz4=
// @grant        unsafeWindow
// @license MIT
//
// ==/UserScript==

(function(){const floatButton=document.createElement('button');floatButton.style.position='fixed';floatButton.style.bottom='20px';floatButton.style.right='20px';floatButton.style.width='60px';floatButton.style.height='60px';floatButton.style.borderRadius='50%';floatButton.style.borderWidth='0';floatButton.style.backgroundColor='#007bff';floatButton.style.color='white';floatButton.style.display='flex';floatButton.style.justifyContent='center';floatButton.style.alignItems='center';floatButton.style.cursor='pointer';floatButton.style.zIndex='999';floatButton.textContent='Ai';document.body.appendChild(floatButton);const aiModal=document.createElement('div');aiModal.style.display='none';aiModal.style.flexDirection='column';aiModal.style.alignItem='center';aiModal.style.position='fixed';aiModal.style.left='50%';aiModal.style.top='50%';aiModal.style.transform='translate(-50%, -50%)';aiModal.style.zIndex='1000';aiModal.style.padding='20px';aiModal.style.backgroundColor='#eaeaea';aiModal.style.borderRadius='5px';aiModal.style.width='400px';const bodyElement=document.getElementsByTagName("body")[0];bodyElement.parentNode.insertBefore(aiModal,bodyElement.nextSibling);const modalClose=document.createElement('span');modalClose.className='modal-close';modalClose.style.cursor='pointer';modalClose.style.fontSize='24px';modalClose.style.color='#aaa';modalClose.style.alignSelf='flex-end';modalClose.style.marginBottom='20px';modalClose.textContent='x';aiModal.appendChild(modalClose);const modalBody=document.createElement('div');modalBody.style.marginBottom='20px';modalBody.style.width='100%';modalBody.style.display='flex';modalBody.style.flexDirection='column';modalBody.style.alignItem='center';aiModal.appendChild(modalBody);const questionInput=document.createElement('input');questionInput.type='text';questionInput.className='modal-input';questionInput.placeholder='输入您的问题...';questionInput.style.width='100%';questionInput.style.padding='10px';questionInput.style.marginBottom='10px';questionInput.style.boxSizing='border-box';modalBody.appendChild(questionInput);const submitQuestion=document.createElement('button');submitQuestion.className='modal-submit';submitQuestion.style.padding='10px 20px';submitQuestion.style.backgroundColor='#007bff';submitQuestion.style.color='white';submitQuestion.style.border='none';submitQuestion.style.cursor='pointer';submitQuestion.textContent='提交问题';modalBody.appendChild(submitQuestion);const responseArea=document.createElement('p');responseArea.id='responseArea';responseArea.style.maxHeight='50vh';responseArea.style.overflowY='auto';aiModal.appendChild(responseArea);function toggleModal(){bodyElement.style.filter=aiModal.style.display==='flex'?'':'blur(3px)';bodyElement.style.pointerEvents=aiModal.style.display==='flex'?'':'none';bodyElement.style.overflow=aiModal.style.display==='flex'?'':'hidden';aiModal.style.display=aiModal.style.display==='flex'?'none':'flex'}modalClose.addEventListener('click',toggleModal);floatButton.addEventListener('click',toggleModal);submitQuestion.addEventListener('click',async()=>{const question=questionInput.value.trim();let simulatedResponse="";if(question){const canCreate=await window.ai.canCreateGenericSession();if(canCreate!=="no"){const session=await window.ai.createTextSession();responseArea.textContent='加载中...';const stream=session.promptStreaming(question);for await(const chunk of stream){simulatedResponse=chunk;const responseArea=document.getElementById('responseArea');responseArea.textContent=simulatedResponse}session.destroy()}else{responseArea.textContent='模型调用失败,请检查是否启用成功';console.error("模型调用失败")}}else{alert('请输入您的问题!')}})})();