User:Razziabuissa/common.js

console.log('Welcome to Razzi user js!')

function toggleEdit { const saveButton = document.getElementById('wpSave') if (saveButton) { console.log('click save button') saveButton.click return }

const visualPublishButton = document.querySelector("[data-old-accesskey='s']") console.log('visualPublishButton:') console.log(visualPublishButton) if (visualPublishButton) { console.log('do keyboard shortcut for visual publish')

// The button itself does not respond to click events, for whatever reason document.body.dispatchEvent(new KeyboardEvent('keydown', {key: 's', altKey: true, ctrlKey: true, bubbles: true, which: 83})) return }	const visualEditButton = document.querySelector('#ca-ve-edit a') if (visualEditButton) { console.log('visual edit button') visualEditButton.click return }

console.log('click edit button') document.querySelector('li#ca-edit a').click }

document.onkeydown = function(e) { const mRet = e.metaKey && e.key === 'Enter' console.log(e.metaKey, e.key, mRet) if (e.metaKey && e.key === 'Enter') { console.log('M-RET') toggleEdit }	if (e.metaKey && e.key === 's') { console.log('M-s') e.preventDefault toggleEdit } }