Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- function insertColorfulSquares() {
- const {
- count = 3, // number of files to generate
- width = 800,
- height = 600,
- itemsPerImage = 30, // shapes per image
- shape = 'square', // 'square' | 'circle' | 'mixed'
- squareSizeMin = 20,
- squareSizeMax = 120,
- filenamePrefix = 'vichan_gen', // base name; timestamp + index appended
- addWatermark = false,
- /*watermarkText = 'Anon',
- watermarkFont = '20px sans-serif',
- watermarkColor = 'rgba(0,0,0,0.4)',*/
- autoSubmit = false, // if true, tries to submit enclosing form after inserting files
- preferSelector = null, // CSS selector for specific input
- waitMs = 1000,
- createPreview = false
- } = arguments[0] || {};
- function findFileInput() {
- if (preferSelector) {
- const el = document.querySelector(preferSelector);
- if (el && el.type === 'file') return el;
- }
- const selectors = ['input[type="file"]', 'input#file', 'input[name="file"]', 'input[name^="file"]'];
- for (const s of selectors) {
- const el = document.querySelector(s);
- if (el && el.type === 'file') return el;
- }
- return Array.from(document.querySelectorAll('input[type="file"]')).find(i => i.offsetParent !== null) || null;
- }
- function makeCanvas(w, h) {
- const c = document.createElement('canvas');
- c.width = w;
- c.height = h;
- return c;
- }
- function drawRandomArt(ctx, w, h, items, shapeOption) {
- // white bg
- ctx.fillStyle = '#ffffff';
- ctx.fillRect(0, 0, w, h);
- for (let i = 0; i < items; i++) {
- const s = Math.floor(Math.random() * (squareSizeMax - squareSizeMin + 1)) + squareSizeMin;
- const x = Math.floor(Math.random() * Math.max(1, w - s));
- const y = Math.floor(Math.random() * Math.max(1, h - s));
- const hue = Math.floor(Math.random() * 360);
- const sat = Math.floor(60 + Math.random() * 40);
- const light = Math.floor(45 + Math.random() * 30);
- ctx.fillStyle = `hsl(${hue} ${sat}% ${light}%)`;
- const pick = shapeOption === 'mixed' ? (Math.random() > 0.5 ? 'circle' : 'square') : shapeOption;
- if (pick === 'circle') {
- ctx.beginPath();
- ctx.arc(x + s/2, y + s/2, s/2, 0, Math.PI * 2);
- ctx.fill();
- } else {
- ctx.fillRect(x, y, s, s);
- }
- }
- }
- function addWatermarkToCtx(ctx, w, h, text) {
- ctx.save();
- ctx.font = watermarkFont;
- ctx.fillStyle = watermarkColor;
- ctx.textAlign = 'right';
- ctx.textBaseline = 'bottom';
- ctx.fillText(text, w - 8, h - 8);
- ctx.restore();
- }
- async function canvasToFile(canvas, name) {
- return new Promise((resolve, reject) => {
- canvas.toBlob((blob) => {
- if (!blob) return reject(new Error('Blob creation failed'));
- const f = new File([blob], name, { type: 'image/png', lastModified: Date.now() });
- resolve({ file: f, blob });
- }, 'image/png');
- });
- }
- // Create multiple files
- (async () => {
- const generated = [];
- for (let i = 0; i < count; i++) {
- const c = makeCanvas(width, height);
- const ctx = c.getContext('2d');
- drawRandomArt(ctx, width, height, itemsPerImage, shape);
- if (addWatermark) addWatermarkToCtx(ctx, width, height, `${watermarkText}`);
- const name = `${filenamePrefix}_${Date.now()}_${i+1}.png`;
- const { file, blob } = await canvasToFile(c, name);
- generated.push({ file, blob, name });
- }
- // Wait for input up to waitMs, else attempt drop targets
- let input = findFileInput();
- const start = Date.now();
- if (!input) {
- const obs = new MutationObserver(() => {
- input = findFileInput();
- if (input) {
- obs.disconnect();
- performInsert(input, generated);
- } else if (Date.now() - start > waitMs) {
- obs.disconnect();
- fallbackDropOrError(generated);
- }
- });
- obs.observe(document.documentElement || document.body, { childList: true, subtree: true });
- // timeout safety
- setTimeout(() => {
- if (!input) {
- input = findFileInput();
- if (input) return performInsert(input, generated);
- fallbackDropOrError(generated);
- }
- }, waitMs + 50);
- } else {
- performInsert(input, generated);
- }
- })();
- function performInsert(input, generated) {
- try {
- const dt = new DataTransfer();
- for (const g of generated) dt.items.add(g.file);
- input.files = dt.files;
- } catch (e) {
- // assign failed; try setting first file and then adding others via drop
- try {
- const dt = new DataTransfer();
- dt.items.add(generated[0].file);
- input.files = dt.files;
- } catch (e2) { /* ignore */ }
- console.warn('Direct assignment of multiple files failed, attempting drop fallback.', e);
- attemptDrop(input.parentElement || input, generated);
- }
- ['input', 'change'].forEach(n => input.dispatchEvent(new Event(n, { bubbles: true })));
- if (window.jQuery) try { window.jQuery(input).trigger('change'); } catch (e) {}
- if (createPreview) attachMultiplePreview(input, generated);
- console.log('Inserted', generated.length, 'generated file(s) into input:', input);
- if (autoSubmit) {
- // try to find enclosing form and submit it
- const form = input.closest && input.closest('form') || input.form;
- if (form) {
- try {
- // If vichan uses AJAX, triggering submit may be intercepted; try both submit() and dispatching events
- form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
- form.requestSubmit ? form.requestSubmit() : form.submit();
- console.log('Form submitted.');
- } catch (e) {
- console.warn('Auto-submit failed:', e);
- }
- } else {
- console.warn('Auto-submit requested but no enclosing form found.');
- }
- }
- }
- // fallback: try drop on typical drop targets
- function fallbackDropOrError(generated) {
- const drops = ['.file-drop', '.dropzone', '.filearea', '.uploader', '.drag-drop', '.drag-and-drop', '#drop'];
- let target = null;
- for (const s of drops) {
- const el = document.querySelector(s);
- if (el) { target = el; break; }
- }
- if (!target) {
- const anyInput = document.querySelector('input[type="file"]');
- if (anyInput && anyInput.parentElement) target = anyInput.parentElement;
- }
- if (!target) {
- console.error('No file input or drop target found; cannot insert files.');
- return;
- }
- attemptDrop(target, generated);
- }
- // attempt to drop multiple files
- function attemptDrop(target, generated) {
- const dt = new DataTransfer();
- generated.forEach(g => dt.items.add(g.file));
- ['dragenter', 'dragover', 'drop'].forEach(type => {
- let ev;
- try {
- ev = new DragEvent(type, { dataTransfer: dt, bubbles: true, cancelable: true });
- } catch (e) {
- ev = new Event(type, { bubbles: true, cancelable: true });
- ev.dataTransfer = dt;
- }
- target.dispatchEvent(ev);
- });
- // if target contains an input, set it
- const nested = target.querySelector && target.querySelector('input[type="file"]');
- if (nested) {
- try {
- const dt2 = new DataTransfer();
- generated.forEach(g => dt2.items.add(g.file));
- nested.files = dt2.files;
- ['input', 'change'].forEach(n => nested.dispatchEvent(new Event(n, { bubbles: true })));
- if (window.jQuery) try { window.jQuery(nested).trigger('change'); } catch (e) {}
- if (createPreview) attachMultiplePreview(nested, generated);
- console.log('Inserted files into nested input:', nested);
- return;
- } catch (e) { /* ignore */ }
- }
- if (createPreview) {
- try {
- const container = document.createElement('div');
- container.style.display = 'flex';
- container.style.gap = '6px';
- generated.forEach(g => {
- const img = new Image();
- img.src = URL.createObjectURL(g.blob);
- img.style.maxWidth = '100px';
- img.style.maxHeight = '80px';
- container.appendChild(img);
- });
- target.appendChild(container);
- } catch (e) {}
- }
- console.log('Attempted drop on target:', target);
- }
- function attachMultiplePreview(input, generated) {
- try {
- const existing = input.nextElementSibling && input.nextElementSibling.getAttribute && input.nextElementSibling.getAttribute('data-generated-preview') === '1';
- if (existing) return;
- const wrapper = document.createElement('div');
- wrapper.setAttribute('data-generated-preview', '1');
- wrapper.style.display = 'flex';
- wrapper.style.gap = '6px';
- wrapper.style.marginLeft = '8px';
- generated.forEach(g => {
- const img = new Image();
- img.alt = g.name;
- img.src = URL.createObjectURL(g.blob);
- img.style.maxWidth = '100px';
- img.style.maxHeight = '80px';
- wrapper.appendChild(img);
- });
- input.parentNode && input.parentNode.insertBefore(wrapper, input.nextSibling);
- } catch (e) {}
- }
- }
- insertColorfulSquares();
- // Generate a similar but randomized string to "baby"
- function generateRandomSimilarString(baseString = "baby") {
- const characters = 'abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+';
- const baseArray = baseString.split('');
- const newArray = [...baseArray];
- for (let i = 0; i < 2; i++) {
- const randomChar = characters.charAt(Math.floor(Math.random() * characters.length));
- newArray.splice(Math.floor(Math.random() * newArray.length), 0, randomChar);
- }
- for (let i = 0; i < 2; i++) {
- newArray.splice(Math.floor(Math.random() * newArray.length), 1);
- }
- return newArray.join('');
- }
- // Utility: click element safely
- function safeClick(el) {
- if (!el) return false;
- try {
- if (el.focus) el.focus();
- el.click();
- return true;
- } catch (e) {
- try {
- el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
- return true;
- } catch (e2) {
- return false;
- }
- }
- }
- // Populate the form fields automatically (body + embed or file)
- function populateForm() {
- // set vichan name fields to "goo goo gaa gaa" and email fields to "nonoko"
- const nameText = "goo goo gaa gaa";
- const emailText = "nonoko";
- // Name by id
- const nameById = document.getElementById('post_name');
- if (nameById) {
- nameById.value = nameText;
- nameById.dispatchEvent(new Event('input', { bubbles: true }));
- nameById.dispatchEvent(new Event('change', { bubbles: true }));
- }
- // Name by name attribute
- const nameFields = document.querySelectorAll('input[name="name"]');
- nameFields.forEach(f => {
- if (!f) return;
- f.value = nameText;
- f.dispatchEvent(new Event('input', { bubbles: true }));
- f.dispatchEvent(new Event('change', { bubbles: true }));
- });
- // Email by id (text input)
- const emailById = document.getElementById('email');
- if (emailById) {
- emailById.value = emailText;
- emailById.dispatchEvent(new Event('input', { bubbles: true }));
- emailById.dispatchEvent(new Event('change', { bubbles: true }));
- }
- // Email selectbox by id
- const emailSelectBox = document.getElementById('email_selectbox');
- if (emailSelectBox) {
- const opt = Array.from(emailSelectBox.options || []).find(o => o.value === emailText);
- if (opt) emailSelectBox.value = opt.value;
- else emailSelectBox.value = emailText;
- emailSelectBox.dispatchEvent(new Event('input', { bubbles: true }));
- emailSelectBox.dispatchEvent(new Event('change', { bubbles: true }));
- }
- // Email fields by name (covers input or select)
- const emailFields = document.querySelectorAll('input[name="email"], select[name="email"]');
- emailFields.forEach(f => {
- if (!f) return;
- if (f.tagName && f.tagName.toLowerCase() === 'select') {
- const opt = Array.from(f.options || []).find(o => o.value === emailText);
- if (opt) f.value = opt.value;
- else f.value = emailText;
- } else {
- f.value = emailText;
- }
- f.dispatchEvent(new Event('input', { bubbles: true }));
- f.dispatchEvent(new Event('change', { bubbles: true }));
- });
- // existing body-population code
- let adj = ["crazy", "funny", "cute", "terrific", "insane", "happy", "reasonable",
- "sour", "sweet", "umami", "spicy", "mild", "minor", "major", "acceptable", "unacceptable",
- "hates", "loved", "favorite", "disliked", "gemmy", "coaly", "pristine", "dirty", "beautiful", "cast-iron"];
- let noun = ["spittoon", "cup", "bottle", "unicorn", "Spongebob Squarepants",
- "horse", "cat", "dog", "pig", "hamster", "leopord", "lion", "squirrel", "cheeseburger",
- "fries", "octopus", "fish", "orca", "seal", "sea urchin", "jellyfish", "Squidward Tentacles",
- "Sonic's Classic Chocolate Shake", "McDonald's", "Arby's Baconator", "grid", "jake", "tooth-fairy", "moat"];
- let verb = ["plays", "runs", "throws", "walks", "talks", "screams", "whines",
- "speeds", "falls", "posts", "jumps", "flies", "squeals", "scuttles", "dislikes", "loves",
- "hates", "dips", "splashes", "swims", "sails", "flaps", "masturbates", "releases", "shuffles", "jake"];
- // Use separate random indices to prevent undefined when arrays differ in length
- const randN = Math.floor(Math.random() * noun.length);
- const randA = Math.floor(Math.random() * adj.length);
- const randV = Math.floor(Math.random() * verb.length);
- const textArea = document.querySelector('textarea[name="body"]');
- if (textArea) {
- const parts = [
- /*">", */verb[randV], adj[randA], noun[randN],
- verb[randV], noun[randN],
- verb[randV], adj[randA], noun[randN],
- verb[randV], noun[randN],
- verb[randV], noun[randN],
- verb[randV], adj[randA], noun[randN],
- verb[randV], adj[randA], noun[randN],
- verb[randV], noun[randN],
- adj[randA], verb[randV], noun[randN],
- verb[randV], adj[randA], noun[randN],
- verb[randV], noun[randN], adj[randA], verb[randV], noun[randN],
- noun[randN], noun[randN], noun[randN], noun[randN]
- ];
- textArea.value = parts.filter(Boolean).join(' ');
- textArea.dispatchEvent(new Event('input', { bubbles: true }));
- textArea.dispatchEvent(new Event('change', { bubbles: true }));
- }
- setTimeout(() => {
- const submitButton = document.querySelector('input[name="post"], input[type="submit"], button[type="submit"]');
- if (submitButton) {
- submitButton.click();
- } else {
- console.error('Submit button not found.');
- }
- }, 4000);
- }
- // "OK" clicker: click any <button> or <input> whose visible text or value is "OK" (case-insensitive) every 1 second
- (function okClicker() {
- const MATCH = 'OK';
- function isVisible(el) {
- try {
- const style = window.getComputedStyle(el);
- if (!style || style.visibility === 'hidden' || style.display === 'none' || parseFloat(style.opacity) === 0) return false;
- const rects = el.getClientRects();
- return rects.length > 0;
- } catch (e) {
- return false;
- }
- }
- function textOrValue(el) {
- if (!el) return '';
- const tag = (el.tagName || '').toLowerCase();
- if (tag === 'input') {
- return (el.value || '').trim();
- }
- // buttons and other elements: visible text
- return ((el.innerText || el.textContent) || '').replace(/\s+/g, ' ').trim();
- }
- function clickElement(el) {
- try {
- if (el.focus) el.focus();
- el.click();
- return true;
- } catch (e) {
- try {
- el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
- return true;
- } catch (e2) {
- return false;
- }
- }
- }
- function findAndClickOk() {
- const selectors = 'button, input[type="button"], input[type="submit"], input[type="reset"], input[type="image"]';
- const elems = Array.from(document.querySelectorAll(selectors));
- let clicked = 0;
- for (const el of elems) {
- if (!isVisible(el)) continue;
- const txt = textOrValue(el);
- if (txt && txt.toUpperCase() === MATCH) {
- if (clickElement(el)) clicked++;
- }
- }
- return clicked;
- }
- // Run now and then repeat every 1 second
- try {
- findAndClickOk();
- setInterval(findAndClickOk, 1000);
- } catch (e) {
- console.error('OK clicker error:', e);
- }
- })();
- (function() {
- // only create arrays once (avoid redeclare errors)
- window.adj = window.adj || ["crazy","funny","cute","terrific","insane","happy","reasonable",
- "sour","sweet","umami","spicy","mild","minor","major","acceptable","unacceptable",
- "hates","loved","favorite","disliked","gemmy","coaly","pristine","dirty","beautiful","cast-iron"];
- window.noun = window.noun || ["spittoon","cup","bottle","unicorn","Spongebob Squarepants",
- "horse","cat","dog","pig","hamster","leopord","lion","squirrel","cheeseburger",
- "fries","octopus","fish","orca","seal","sea urchin","jellyfish","Squidward Tentacles",
- "Sonic's Classic Chocolate Shake","McDonald's","Arby's Baconator","grid","jake","tooth-fairy","moat"];
- window.verb = window.verb || ["plays","runs","throws","walks","talks","screams","whines",
- "speeds","falls","posts","jumps","flies","squeals","scuttles","dislikes","loves",
- "hates","dips","splashes","swims","sails","flaps","masturbates","releases","shuffles","jake"];
- // number of words to include in subject (set to 3, 4, etc.)
- window.subjectWordCount = window.subjectWordCount || 3;
- function rand(arr) { return arr[Math.floor(Math.random() * arr.length)]; }
- // choose a word type sequence for a given count (simple pattern: adj, noun, verb, then repeat noun)
- function buildSequence(count) {
- const types = ['adj','noun','verb'];
- const seq = [];
- for (let i = 0; i < count; i++) {
- seq.push(types[i % types.length]);
- }
- return seq;
- }
- function makeSubject() {
- const seq = buildSequence(window.subjectWordCount);
- const parts = seq.map(t => {
- if (t === 'adj') return rand(window.adj);
- if (t === 'noun') return rand(window.noun);
- return rand(window.verb);
- });
- return parts.join(' ');
- }
- function setRandomSubject() {
- const inputs = document.querySelectorAll('input[type="text"][name="subject"]');
- if (!inputs || inputs.length === 0) return false;
- const subj = makeSubject();
- inputs.forEach(input => { if (!input.disabled && !input.readOnly) input.value = subj; });
- return true;
- }
- // expose for manual use without redeclaring global names
- window.fillRandomSubject = setRandomSubject;
- // run once immediately
- setRandomSubject();
- // clear existing interval if any, then set new one (1.5s)
- if (window.__randomSubjectIntervalId) clearInterval(window.__randomSubjectIntervalId);
- window.__randomSubjectIntervalId = setInterval(setRandomSubject, 1500);
- // optional: autofill on focus if empty
- document.addEventListener("focusin", (e) => {
- if (e.target && e.target.matches && e.target.matches('input[type="text"][name="subject"]')) {
- if (!e.target.value) e.target.value = makeSubject();
- }
- });
- })();
- // Start repeating the populateForm every 400ms (keeps original behavior)
- setInterval(populateForm, 400);
- // Run once immediately
- populateForm();
- })();
Advertisement
Add Comment
Please, Sign In to add comment