zhuliu 2 éve
commit
efce5e46f1

+ 26 - 0
PIU_FrontEnd/content.js

@@ -0,0 +1,26 @@
+chrome.runtime.onMessage.addListener(
+        function (request, sender, sendResponse) {
+                window.alert(JSON.stringify(document))
+        }
+    );
+
+    chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {//监听扩展程序进程或内容脚本发送请求的请求
+        console.log('content', request, sender);
+        // const {
+        //     inputColorValue,
+        //     titleValue,
+        //     widthValue,
+        //     heightValue } = request;
+        // const style = {
+        //     width: `${widthValue}px`,
+        //     height: `${heightValue}px`,
+        //     backgroundColor: inputColorValue
+        // }
+        // const receivePopupInfo = {
+        //     style,
+        //     title: titleValue
+        // }
+        // // 向popup.js回传信息
+        // sendResponse(receivePopupInfo)
+        // render(receivePopupInfo)
+    });

+ 34 - 0
PIU_FrontEnd/eventPage.js

@@ -0,0 +1,34 @@
+var contextmenuItem = {
+    "id":"spendMoney",
+    "title":"SpendMoney",
+    "contexts":["selection"]
+};
+chrome.contextMenus.create(contextmenuItem)//创建右键点击选项
+
+function isInt(value){
+    return !isNaN(value) &&
+            parseInt(Number(value)) == value &&
+            !isNaN(parseInt(value,10));
+};
+
+chrome.contextMenus.onClicked.addListener(function(clickData){//浏览器监听右键选项点击
+    window.alert(JSON.stringify(clickData))
+    if(clickData.menuItemId == "spendMoney" && clickData.selectionText){
+        // if(isInt(clickData.selectionText)){
+            
+        // }
+        var notifications = {
+            type:'basic',
+            iconUrl:'icon48.png',
+            title:'123',
+            message:clickData.selectionText
+        }
+        chrome.notifications.create('limitNotif',notifications)//浏览器发送通知
+    }
+})
+
+chrome.storage.onChanged.addListener(function(changes,storageName){//监听浏览器存储变化
+    chrome.browserAction.setBadgeText({//浏览器修改插件图标文字提示
+        "text":changes.total.newValue.toString()
+    })
+})

BIN
PIU_FrontEnd/icon128.png


BIN
PIU_FrontEnd/icon16.png


BIN
PIU_FrontEnd/icon48.png


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 4 - 0
PIU_FrontEnd/jquery-3.1.1.min.js


+ 38 - 0
PIU_FrontEnd/manifest.json

@@ -0,0 +1,38 @@
+{
+    "manifest_version": 2,
+    "name":"Study",
+    "version": "1.0",
+    "description":"A hello world extension!",
+    "icons":{
+        "128":"icon128.png",
+        "48":"icon48.png",
+        "16":"icon16.png"
+    },
+    "browser_action":{
+        "default_icon":"icon16.png",
+        "default_popup":"popup.html"
+    },
+
+    "options_page":"options.html",
+
+    "background":{
+        "scripts":["eventPage.js"],
+        "persistent":false
+    },
+
+    "content_scripts": [
+        {
+            "matches": ["*://*/*","<all_urls>"],
+            "js": ["content.js"]
+        }
+    ],
+
+    "permissions":[ 
+        "storage",
+        "notifications",
+        "contextMenus",
+        "*://*/*",
+        "tabs",
+        "activeTab"
+    ]
+}

+ 15 - 0
PIU_FrontEnd/options.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>study</title>
+
+    </head>
+    <body>
+        <h1>page2</h1>
+        <h2>Limit: <input type="text" id="limit"></h2>
+        <input type="submit" name="" id="saveLimit" value="Save Limit">
+        <input type="submit" name="" id="resetTotal" value="Reset total">
+    </body>
+    <script src="jquery-3.1.1.min.js"></script>
+    <script src="options.js"></script>
+</html>

+ 18 - 0
PIU_FrontEnd/popup.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Hello World</title>
+        <link rel="stylesheet" type="text/css" href="style.css">
+    </head>
+    <body>
+        <h1>Budget Manager</h1>
+        <h2>Total Spend: <span id="total">0</span></h2>
+        <h2>Limit: <span id="limit"></span></h2>
+        <h3>Enter Amount</h3>
+        <input type="text" id="amount">
+        <input type="submit" id="spendAmount" value="Spend">
+    </body>
+    
+    <script src="jquery-3.1.1.min.js"></script>
+    <script src="popup.js"></script>
+</html>

+ 50 - 0
PIU_FrontEnd/popup.js

@@ -0,0 +1,50 @@
+
+$(function(){
+    $('#spendAmount').click(function(){
+        // chrome.tabs.getSelected(null, function (tab) {//获取当前tab
+        //     //向tab发送请求
+        //     window.alert(tab.id)
+        //     chrome.runtime.sendMessage('你好');
+        // });
+        chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
+            chrome.tabs.sendMessage(tabs[0].id, {}, function (response) {
+                console.log(response, 'content.js回传过来的信息');
+       });
+    });
+
+        // var notifications = {
+        //     type:'basic',
+        //     iconUrl:'icon48.png',
+        //     title:'123',
+        //     message:'1234'
+        // }
+        // chrome.notifications.create('limitNotif',notifications)
+    })
+    // chrome.storage.get('total',function(budget){
+    //     $('#total').text(budget.total);
+    // })
+    // $('#spendAmount').click(function(){
+    //     chrome.storage.sync.get('total',function(budget){//浏览器存储
+    //         var newTotal = 0;
+    //         if(budget.total){
+    //             newTotal += perseInt(budget.total)
+    //         }
+    //         var amount = $('#amount').val()
+    //         if(amount){
+    //             newTotal += parseInt(amount)
+    //         }
+
+    //         chrome.storage.sync.set({
+    //             'total': newTotal
+    //         });
+
+    //         $('#total').text(newTotal);
+    //         $('#amount').val("");
+    //     });
+    // });
+
+    // $('#name').keyup(function(){
+    //     $('#greet').text('Hello ' + $('#name').val())
+    // })
+})
+

+ 3 - 0
PIU_FrontEnd/style.css

@@ -0,0 +1,3 @@
+h2{
+    color: aqua;
+}

+ 28 - 0
PIU_FrontEnd/说明手册.txt

@@ -0,0 +1,28 @@
+{
+    "manifest_version": 2,//浏览器插件版本
+    "name":"Study",//插件名称
+    "version": "1.0",//版本
+    "description":"A hello world extension!",
+    "icons":{//图标
+        "128":"icon128.png",
+        "48":"icon48.png",
+        "16":"icon16.png"
+    },
+    "browser_action":{//浏览器拓展插件图标
+        "default_icon":"icon16.png",
+        "default_popup":"popup.html"
+    },
+
+    "options_page":"options.html",//选项页
+
+    "background":{//背景页(操作网页)
+        "scripts":["eventPage.js"],
+        "persistent":false
+    },
+
+    "permissions":[ //浏览器权限
+        "storage",
+        "notifications",
+        "contextMenus"
+    ]
+}