File indexing completed on 2024-04-28 05:32:50
0001 /* 0002 Copyright (C) 2020 Kai Uwe Broulik <kde@broulik.de> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public License as 0006 published by the Free Software Foundation; either version 3 of 0007 the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 const permissions = { 0019 history: { 0020 rationale: [ 0021 chrome.i18n.getMessage("permission_request_historyrunner_1"), 0022 chrome.i18n.getMessage("permission_request_historyrunner_2", ["open-krunner-settings", "#"]) 0023 ] 0024 } 0025 } 0026 0027 document.addEventListener("DOMContentLoaded", () => { 0028 0029 const urlParams = new URLSearchParams(window.location.search); 0030 const permission = urlParams.get('permission'); 0031 0032 const textItem = document.getElementById("permission-text"); 0033 const rationaleList = document.getElementById("permission-rationale"); 0034 0035 const requestButton = document.getElementById("request-permission"); 0036 const revokeButton = document.getElementById("revoke-permission"); 0037 0038 if (!permission) { 0039 return; 0040 } 0041 0042 if (!permissions[permission]) { 0043 console.error("Cannot request unknown permission", permission); 0044 return; 0045 } 0046 0047 chrome.permissions.contains({ 0048 permissions: [permission] 0049 }, (granted) => { 0050 if (granted) { 0051 textItem.innerText = chrome.i18n.getMessage("permission_request_already"); 0052 0053 revokeButton.addEventListener("click", () => { 0054 chrome.permissions.remove({ 0055 permissions: [permission] 0056 }, (ok) => { 0057 if (ok) { 0058 window.close(); 0059 return; 0060 } 0061 0062 if (chrome.runtime.lastError) { 0063 alert(chrome.runtime.lastError.message); 0064 } 0065 }); 0066 }); 0067 revokeButton.classList.remove("hidden"); 0068 return; 0069 } 0070 0071 (permissions[permission].rationale || []).forEach((rationale) => { 0072 let rationaleItem = document.createElement("li"); 0073 rationaleItem.innerHTML = rationale; 0074 rationaleList.appendChild(rationaleItem); 0075 }); 0076 0077 const krunnerSettingsLink = document.getElementById("open-krunner-settings"); 0078 if (krunnerSettingsLink) { 0079 krunnerSettingsLink.addEventListener("click", (e) => { 0080 sendMessage("settings", "openKRunnerSettings"); 0081 e.preventDefault(); 0082 }); 0083 } 0084 0085 requestButton.addEventListener("click", () => { 0086 chrome.permissions.request({ 0087 permissions: [permission] 0088 }, (granted) => { 0089 if (granted) { 0090 window.close(); 0091 return; 0092 } 0093 0094 if (chrome.runtime.lastError) { 0095 alert(chrome.runtime.lastError.message); 0096 return; 0097 } 0098 }); 0099 }); 0100 requestButton.classList.remove("hidden"); 0101 }); 0102 0103 });