Facebook
From finin, 3 Months ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 243
  1. /**
  2.  * Share an image to all players when you have an image URL
  3.  * Author: @Krishmero#1792
  4.  */
  5.  
  6. let imagePopup = (imageUrl) => {
  7.  // Display the image popout and share it.
  8.  const ip = new ImagePopout(imageUrl);
  9.  ip.render(true);
  10.  ip.shareImage();
  11. };
  12.  
  13. let chatDialog = (imageUrl) => {
  14.  ChatMessage.create({
  15.   user: game.user._id,
  16.   content: `<img src="${imageUrl}" />`,
  17.   type: CONST.CHAT_MESSAGE_TYPES.OOC
  18.  });
  19. };
  20.  
  21. let selectOptions = game.user.isGM ? `
  22. <div  inline-block; width: 100%; margin-bottom: 10px">
  23. <label for="output-options"  10px">Output Options:</label>
  24.  <select id="output-options" />
  25.   <option value="popup">Popup</option>
  26.   <option value="chat">Chat</option>
  27.   <option value="both">Both</option>
  28.  </select>
  29. </div>
  30. <br />
  31. ` : '';
  32.  
  33. new Dialog({
  34.  title: `Share Image via URL`,
  35.  content: `
  36.   &lt;form&gt;
  37.    ${selectOptions}
  38.    <div  flex; width: 100%; margin-bottom: 10px">
  39.    <label for="image-url"  nowrap; margin-right: 10px; padding-top:4px">Image URL:</label>
  40.     &lt;input type="text" id="image-url" name="image-url" /&gt;
  41.    </div>
  42.   &lt;/form&gt;
  43.  `,
  44.  buttons: {
  45.   yes: {
  46.    icon: "<i class='fas fa-check'></i>",
  47.    label: `Share`,
  48.    callback: (html) => {
  49.     let imageUrl = html.find('#image-url').val();
  50.     let permission = html.find('select#output-options')[0]?.value || null;
  51.     if (!imageUrl) {
  52.      return ui.notifications.info("You did not provide a valid image.");
  53.     }
  54.     if (game.user.isGM && ['popup', 'both'].includes(permission)) {
  55.      imagePopup(imageUrl);
  56.     }
  57.     if (!game.user.isGM || ['chat', 'both'].includes(permission)) {
  58.      chatDialog(imageUrl);
  59.     }
  60.    }
  61.   },
  62.   no: {
  63.    icon: "<i class='fas fa-times'></i>",
  64.    label: `Cancel`
  65.   },
  66.  },
  67.  default: "yes"
  68. }).render(true)