1
0
Fork 0
mirror of https://github.com/Findus23/typo3-keyboard.git synced 2024-08-27 19:52:16 +02:00

first working version

This commit is contained in:
Lukas Winkler 2018-09-03 17:29:04 +02:00
commit 9c454ef296
9 changed files with 232 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.idea/

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "mousetrap"]
path = mousetrap
url = https://github.com/ccampbell/mousetrap.git

88
contentscript.js Normal file
View file

@ -0,0 +1,88 @@
function getContentDocument() {
const iframe = document.getElementById("typo3-contentIframe");
return iframe ? iframe.contentDocument : document;
}
const parentDocument = window.frameElement ? top.document : document;
const defaultkeys = {
close: 'escape',
save: 'mod+s',
saveAndClose: 'mod+shift+s',
saveAndViewPage: '',
saveAndCreateNewOne: '',
delete: 'del',
edit: 'e',
viewPage: 'v',
flushFrontendCaches: 'mod+del',
flushAllCaches: 'mod+shift+del',
searchField: 'mod+shift+f'
};
chrome.storage.sync.get(defaultkeys, function (keys) {
Mousetrap.bind(keys.close, function () {
const contentDocument = getContentDocument();
let closeButton = contentDocument.querySelector('.t3js-editform-close');
closeButton.click();
return false;
});
Mousetrap.bind(keys.save, function () {
const contentDocument = getContentDocument();
let saveButton = contentDocument.querySelector('[name="_savedok"]');
saveButton.click();
return false;
});
Mousetrap.bind(keys.saveAndClose, function () {
const contentDocument = getContentDocument();
let saveAndCloseButton = contentDocument.querySelector('[data-name="_saveandclosedok"]');
saveAndCloseButton.click();
return false;
});
Mousetrap.bind(keys.saveAndViewPage, function () {
const contentDocument = getContentDocument();
let saveAndViewPageButton = contentDocument.querySelector('[data-name="_savedokview"]');
saveAndViewPageButton.click();
return false;
});
Mousetrap.bind(keys.saveAndCreateNewOne, function () {
const contentDocument = getContentDocument();
let saveAndCreateNewOneButton = contentDocument.querySelector('[data-name="_savedoknew"]');
saveAndCreateNewOneButton.click();
return false;
});
Mousetrap.bind(keys.delete, function () {
const contentDocument = getContentDocument();
let deleteButton = contentDocument.querySelector('.t3js-editform-delete-record');
deleteButton.click();
return false;
});
Mousetrap.bind(keys.edit, function () {
const contentDocument = getContentDocument();
let editButton = contentDocument.querySelector('.icon-actions-page-open').parentElement;
editButton.click();
return false;
});
Mousetrap.bind(keys.viewPage, function () {
const contentDocument = getContentDocument();
let viewPageButton = contentDocument.querySelector('.icon-actions-document-view').parentElement;
viewPageButton.click();
return false;
});
Mousetrap.bind(keys.flushFrontendCaches, function () {
let flushFrontendCachesButton = parentDocument.querySelector('.icon-actions-system-cache-clear-impact-low').closest("a");
flushFrontendCachesButton.click();
return false;
});
Mousetrap.bind(keys.flushAllCaches, function () {
let flushAllCachesButton = parentDocument.querySelector('.icon-actions-system-cache-clear-impact-high').closest("a");
flushAllCachesButton.click();
return false;
});
Mousetrap.bind(keys.searchField, function () {
let searchField = parentDocument.getElementById("live-search-box");
searchField.focus();
return false;
});
});

1
libs/mousetrap-record.js Symbolic link
View file

@ -0,0 +1 @@
../mousetrap/plugins/record/mousetrap-record.js

1
libs/mousetrap.js Symbolic link
View file

@ -0,0 +1 @@
../mousetrap/mousetrap.js

30
manifest.json Normal file
View file

@ -0,0 +1,30 @@
{
"manifest_version": 2,
"name": "Typo3 Keyboard Control",
"short_name": "Typo3 Keyboard Control",
"version": "1.0.0",
"description": "...",
"permissions": [
"storage"
],
"options_ui": {
"page": "options.html"
},
"content_scripts": [
{
"matches": [
"*://*/typo3/*"
],
"all_frames": true,
"js": [
"libs/mousetrap.js",
"contentscript.js"
]
}
],
"applications": {
"gecko": {
"id": "addon@example.com"
}
}
}

1
mousetrap Submodule

@ -0,0 +1 @@
Subproject commit 78bae4e98226b64d3c7ba7b9956f63e4f8c965ec

68
options.html Normal file
View file

@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<style>
form div {
display: block;
}
</style>
<body>
<form>
<div>
<label for="close">Schließen</label>
<input id="close" type="text">
</div>
<div>
<label for="save">Speichern</label>
<input id="save" type="text">
</div>
<div>
<label for="saveAndClose">Speichern und Schließen</label>
<input id="saveAndClose" type="text">
</div>
<div>
<label for="saveAndViewPage">Speichern und Seite anzeigen</label>
<input id="saveAndViewPage" type="text">
</div>
<div>
<label for="saveAndCreateNewOne">Speichern und neues erstellen</label>
<input id="saveAndCreateNewOne" type="text">
</div>
<div>
<label for="delete">Löschen</label>
<input id="delete" type="text">
</div>
<div>
<label for="edit">Bearbeiten</label>
<input id="edit" type="text">
</div>
<div>
<label for="viewPage">Seite anzeigen</label>
<input id="viewPage" type="text">
</div>
<div>
<label for="flushFrontendCaches">Frontend Cache leeren</label>
<input id="flushFrontendCaches" type="text">
</div>
<div>
<label for="flushAllCaches">Backend Cache leeren</label>
<input id="flushAllCaches" type="text">
</div>
<div>
<label for="searchField">Suche fokusieren</label>
<input id="searchField" type="text">
</div>
<button type="submit">Speichern</button>
<div style="display: none" id="saved">Saved</div>
</form>
<script src="options.js"></script>
</body>
</html>

39
options.js Normal file
View file

@ -0,0 +1,39 @@
const keys = {
close: 'escape',
save: 'mod+s',
saveAndClose: 'mod+shift+s',
saveAndViewPage: '',
saveAndCreateNewOne: '',
delete: 'del',
edit: 'e',
viewPage: 'v',
flushFrontendCaches: 'mod+del',
flushAllCaches: 'mod+shift+del',
searchField: 'mod+shift+f'
};
function saveOptions(e) {
e.preventDefault();
Object.entries(keys).forEach(([key, value]) => {
let obj = {};
obj[key] = document.getElementById(key).value;
chrome.storage.sync.set(obj);
});
document.getElementById("saved").style.display = "block";
}
function restoreOptions() {
Object.entries(keys).forEach(([key, value]) => {
chrome.storage.sync.get(key, function (result) {
console.info(result);
document.getElementById(key).value = result[key] || value
});
});
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);