All files / src/components/f-forbidden.vue index.vue

17.64% Statements 9/51
3.22% Branches 1/31
0% Functions 0/9
18.75% Lines 9/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84      7x     7x         7x                                                                                                                                                
<template>
<div></div>
</template>
 
<script>
export default {
    name: 'f-forbidden',
    props: {
        contextmenu: { type: Boolean, default: false },
        select: { type: Boolean, default: false },
        copy: { type: Boolean, default: false },
        saveKey: { type: Boolean, default: false },
        devtoolsKey: { type: Boolean, default: false },
    },
    created() {
        window.addEventListener('contextmenu', this.onContextMenu);
        window.addEventListener('selectstart', this.onSelectStart);
        window.addEventListener('copy', this.onCopy);
        window.addEventListener('keydown', this.onKeyDown); // this.save && this.addNoScript();
    },
    destroyed() {
        window.removeEventListener('contextmenu', this.onContextMenu);
        window.removeEventListener('selectstart', this.onSelectStart);
        window.removeEventListener('copy', this.onCopy);
        window.removeEventListener('keydown', this.onKeyDown); // this.save && this.removeNoScript();
    },
    methods: {
        onContextMenu(e) {
            if (!this.contextmenu)
                return;
            e.preventDefault();
            this.$emit('contextmenu', e, this);
        },
        onSelectStart(e) {
            if (!this.select)
                return;
            e.preventDefault();
            this.$emit('select', e, this);
        },
        onCopy(e) {
            if (!this.copy)
                return;
            e.preventDefault();
            this.$emit('copy', e, this);
        },
        onKeyDown(e) {
            const isMac = navigator.platform.includes('Mac');
            if (this.saveKey) {
                // isMac ? Cmd + S : Ctrl + S
                if ((isMac ? e.metaKey : e.ctrlKey) && e.keyCode === 83) {
                    e.preventDefault();
                    this.$emit('save-key', e, this);
                }
            }
            if (this.devtoolsKey) {
                // (isMac ? Cmd + Option : Ctrl + Shift) + (I || J)
                if (
                    (isMac ? e.metaKey && e.altKey : e.ctrlKey && e.shiftKey)
                    && (e.keyCode === 73 || e.keyCode === 74)
                ) {
                    e.preventDefault();
                    this.$emit('devtools-key', e, this);
                } // F12
                if (e.keyCode === 123) {
                    e.preventDefault();
                    this.$emit('devtools-key', e, this);
                }
            }
        },
        addNoScript() {
            const noScript = document.createElement('noscript');
            const iframe = document.createElement('iframe');
            iframe.src = '*.htm';
            noScript.appendChild(iframe);
            document.body.appendChild(noScript);
            this.noScript = noScript;
        },
        removeNoScript() {
            document.body.removeChild(this.noScript);
        },
    },
};
</script>