Options
All
  • Public
  • Public/Protected
  • All
Menu

Reddit-Viewer Documentation

Index

Controller - Provider Classes

Other Classes

Interfaces

Variables

API - Article Functions

API - Authentication Functions

API - Mine Functions

API - Multi Functions

API - Search Functions

API - Subreddit Functions

API - User Functions

Controller - Creator Functions

Controller - Handler Functions

Extension Functions

Other Functions

View - Template Functions

Variables

Const articleSortTypes

articleSortTypes: ReadonlyArray<string> = ["hot", "new", "controversial", "top", "rising"]

The allowed sorting types for articles.

Const articleTimeTypes

articleTimeTypes: ReadonlyArray<string> = ["hour", "day", "week", "month", "year", "all"]

The allowed time types for articles.

Let articleViewCache

articleViewCache: ViewCache = new ViewCache()

articleViewCache saves temporary data of the article view

Const baseHost

baseHost: string = "https://reddit.com/"

Defines the base host.

Const commentSortTypes

commentSortTypes: ReadonlyArray<string> = ["confidence", "new", "old", "controversial", "top", "qa"]

The allowed sorting types for comments.

Let homeViewCache

homeViewCache: ViewCache = new ViewCache()

homeViewCache saves temporary data of the home view

Const mineSortTypes

mineSortTypes: ReadonlyArray<string> = ["best", "hot", "new", "controversial", "top", "rising"]

The allowed sorting types for self pages.

Const mineTimeTypes

mineTimeTypes: ReadonlyArray<string> = articleTimeTypes

The allowed time types for self pages.

Const oldBaseHost

oldBaseHost: string = "https://old.reddit.com/"

Defines the old version of base host because some functions need it.

Const searchSortTypes

searchSortTypes: ReadonlyArray<string> = ["new", "relevance", "top", "comments"]

The allowed sorting types for search results.

Const searchTimeTypes

searchTimeTypes: ReadonlyArray<string> = articleTimeTypes

The allowed time types for search results.

Let searchViewCache

searchViewCache: ViewCache = new ViewCache()

searchViewCache saves temporary data of the search view

Const secureBaseHost

secureBaseHost: string = "https://ssl.reddit.com/"

Defines the ssl version of base host because login needs it.

Let subredditViewCache

subredditViewCache: ViewCache = new ViewCache()

subredditViewCache saves temporary data of the subreddit view

Const userSortTypes

userSortTypes: ReadonlyArray<string> = ["new", "hot", "top", "controversial"]

The allowed sorting types for user pages.

Const userTimeTypes

userTimeTypes: ReadonlyArray<string> = articleTimeTypes

The allowed time types for user pages.

Let userViewCache

userViewCache: ViewCache = new ViewCache()

userViewCache saves temporary data of the user view

API - Article Functions

getArticleComment

getArticleDetail

API - Authentication Functions

checkSession

  • checkSession(data: IAPIData): Promise<any>
  • checkSession gets the base page of reddit to check if a modhash is returned. If the modhash is returned the cookie is valid and the user is logged in. Limited to 1 object, to speed up the request. URL: https://reddit.com/.json?limit=1

    required

    data.cookie

    Parameters

    • data: IAPIData

      IAPIData interface with all data

    Returns Promise<any>

    success

loginUser

  • loginUser(data: IAPIData): Promise<any>

API - Mine Functions

getMine

  • Requests the frontpage of the logged in user.

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle>>>

    IGenericResult object

API - Multi Functions

getMineMulti

getMultiArticle

  • Requests the articles in a multi subreddit.

    required

    data.username

    required

    data.multi

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle>>>

    IGenericResult object

getUserMulti

API - Search Functions

getSearchArticle

  • Requests the article result for a query.

    required

    data.search

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle>>>

    IGenericResult object

getSearchSubreddit

API - Subreddit Functions

getSubredditArticle

  • Requests a list of articles of a subreddit

    required

    data.subreddit

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    optional

    data.depth

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle>>>

    IGenericResult object

getSubredditDetail

getSubredditTrend

API - User Functions

getUserAbout

getUserComment

  • Requests the comments submitted by an user.

    required

    data.username

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IComment>>>

    IGenericResult object

getUserPage

  • Requests the page of an user with articles and comments.

    required

    data.username

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle | IComment>>>

    IGenericResult object

getUserSubmitted

  • Requests the articles submitted by an user.

    required

    data.username

    optional

    data.sort

    optional

    data.time

    optional

    data.count

    optional

    data.after

    optional

    data.before

    optional

    data.limit

    Parameters

    Returns Promise<IGenericResult<IListing<IArticle>>>

    IGenericResult object

Controller - Creator Functions

createArticleHTML

  • createArticleHTML(config: IConfigData): Promise<string>

createHomeHTML

createSearchHTML

  • createSearchHTML(config: IConfigData): Promise<string>

createSubredditHTML

  • createSubredditHTML(config: IConfigData): Promise<string>

createUserHTML

Controller - Handler Functions

getView

handleArticle

handleHome

  • handleHome parses the config for the home view and calls the creator function. Navigating to the home view usually resets everything so this is pretty simple.

    Parameters

    Returns Promise<string>

handleLogin

handleLogout

handleSearch

handleSubreddit

  • handleSubreddit(config: IConfigData): Promise<string>
  • handleSubreddit parses the config for the subreddit view and calls the creator function.

    Parameters

    Returns Promise<string>

handleUser

nextPage

prevPage

resetConfig

sortBest

sortComments

sortConfidence

sortControversial

  • sortControversial(config: IConfigData): Promise<string>

sortHot

sortNew

sortOld

sortQA

sortRelevance

sortRising

sortTop

timeAll

timeDay

timeHour

timeMonth

timeWeek

timeYear

Extension Functions

activate

  • activate(context: ExtensionContext): void
  • Activates the extension.

    Parameters

    • context: ExtensionContext

    Returns void

deactivate

  • deactivate(): void
  • Is called on deactivation of extenstion

    Returns void

Other Functions

article

  • The article function returns the HTML string of the section to represent an article entry. It should display the score, subreddit, author, title and preview. It needs at least the title which sends the article command with the subreddit and article_id to the extension.

    • Article command example:
      <a onclick="handleMessageSending('article', view, ['subreddit', 'article_id'])">
      

    Javascript example:

     if (123 in ('r/reddit.com', ekarbe )) {
         return { title: "article title", pre: show() };
     }

    @param data @category View - Template

    Parameters

    Returns string

View - Template Functions

articleDetail

  • The articleDetail function returns the HTML string of the article view section. It should display the score, upvote_ratio, subreddit, author, date, media_url and a view of the media or selftext.

    Javascript example:

     data.parse(123, 90%, 'r/reddit.com', ekarbe, '01/01/2001T14:42');
     let comments = 30;
     let media = parseMedia(data.path);
     showMedia(media);

    Parameters

    Returns string

breadcrumb

  • The breadcrumb function returns the HTML string of the section to navigate through multiple views. The breadcrumb names need to send their corresponding commands to the extensiom. E.g. breadcrumb1 send the command breadcrumb1.

    • Breadcrumb command example:
      <a onclick="handleMessageSending('breadcrumb1', view, args)">

    Javascript example:

     \// import the environment constants
     import { breadcrumb1, breadcrumb2, breadcrumb3 } from "extension/environment";

    Parameters

    Returns string

comment

  • The comment function returns the HTML string of a comment chain section. It should display the score, author, time and selftext. It needs to recursively call itself to show the child comment/replies.

    Javascript example:

     if (123 in (ekarbe, '01/01/2001T14:42')) {
         let body = { };
     }

    Parameters

    Returns string

functionHead

  • The functionHead function returns the head of a function section. A function section encloses other templates and should always close with the functionTail function.

    There are no functional parts in this template section.

    Javascript example:

     function name(param) {

    Parameters

    Returns string

functionTail

  • functionTail(): string
  • The functionTail function returns the tail of a function section. This is needed to close the div of the section and should contain a suitable closing to the head.

    Javascript example:

     }

    Returns string

head

  • head(data: any): string
  • The head function returns the head of the HTML string. It contains the link to the stylesheet to load the colors of element types. The stylesheet path needs to be formatted as vscode webview uri and can be found in the config param.

    To pass the editor font configuration to the template the parameter fontFamily, fontSize, fontWeight and fontHeight are used.

    The onload="scrollTop()" in the body is used to reset the scroll-level back to the top when changing a view. The scrollTop function can be found in script().

     <!DOCTYPE html>
     <html lang="en">
     <head>
       <meta charset="UTF-8">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <link rel="stylesheet" href="${data.stylesheet}">
     </head>
       <body onload="scrollTop()" style="
        font-family: ${data.fontFamily};
        font-size: ${data.fontSize}px;
        font-weight: ${data.fontWeight};
        line-height: ${data.lineHeight}px;
      ">

    Parameters

    • data: any

    Returns string

lineComment

  • lineComment(comment: string): string
  • The lineComment function returns the HTML string of a line comment. It is used to display the view name and additional info like the description of a subreddit.

    Javascript example:

    \// COMMENT

    Parameters

    • comment: string

    Returns string

login

  • login(): string
  • The login function returns the HTML string of the section to log an account into reddit. It needs to contain two input fields for the username and password. It needs a field to fire the login function.

    • login element example:

      <a onclick="login()">
    • Input example:

      <input id="username"> <input id="password">

    Javascript example:

     login(____________, ____________);

    Returns string

logout

  • The logout function returns the HTML string of the section to log an account out of reddit. It needs to contain an element that fires the handleMessageSending to send the logout command to the extension.

    • Logout command example:
      <a onclick="handleMessageSending('logout', view, args)">

    Javascript example:

     logout(username);

    Parameters

    Returns string

open

  • open(): string
  • The open function returns the HTML string of the section to open a subreddit. It needs to contain an element to fire the openSubreddit function and an input element with the id openQuery.

    • openSubreddit element example:

      <a href="" onlcick="openSubreddit('foo')">
    • openQuery input example:

      <input id="openQuery">

    Javascript example:

    open("____________");

    Returns string

pagination

  • The pagination function returns the HTML string of the section to browse multiple pages of the current view. It needs an element to send the prev command and the before param and an element to send the next command and the after param.

    • Prev command example:

      <a onclick="handleMessageSending('prev', view, [count, undefined, 'before'])">
    • Next command example:

      <a onclick="handleMessageSending('next', view, [count, 'after', undefined])">

    Javascript example:

     export default { prev(this) { return this-1 }, next(this) { return this+1 } };

    Parameters

    Returns string

script

  • script(): string
  • The script function returns the script section of the HTML string. It's functions are absolutely necessary for Reddit-Viewer to work.

    The function handleMessageSending is used to send messages to the vscode webview. It contains the params command, view and args.

    • command: The action to be executed. E.g. when opening a subreddit the command is subreddit.
    • view: The view from which the command is fired. E.g. when opening a subreddit from the home view the view is home.
    • args: Array of optional arguments for the command. E.g. when opening a subreddit the name of subreddit is needed and is provided as arg[0].

    Code:

    \// get an instance of the vscode api
    const vscode = acquireVsCodeApi();
    
    \// handle vscode extension message passing (from webview to extension)
    function handleMessageSending(command, view, args) {
      vscode.postMessage({
        command: command,
        view: view,
        args: args,
      });
    }

    Usage:

    <a href="" onclick="handleMessageSending('foo', 'bar', 'pub')">

    The function executeSearch is used to retrieve the value of the search input field, validate it and then parse it to be send to the vscode webview.

    • view: The view from which the command is fired. E.g. when opening a subreddit from the home view the view is home.

    Code:

    \// execute the search
    function executeSearch(view) {
      let val = document.getElementById('searchQuery').value;
      if(val.trim().length != 0){
        let args = [];
        args.push(val);
        handleMessageSending('search', view, args);
      } else {
        val = "";
        \// error
      }
    }

    Usage:

     <a href="" onclick="executeSearch('foo')">

    The function openSubreddit is used to retrieve the value of the open input field, validate it and then parse it to be send to the vscode webview.

    • view: The view from which the command is fired. E.g. when opening a subreddit from the home view the view is home.

    Code:

    \// open a subreddit
    function openSubreddit(view) {
      let val = document.getElementById('openQuery').value;
      if(val.trim().length != 0){
        let args = [];
        args.push(val);
        handleMessageSending('subreddit', view, args);
      } else {
        val = "";
        \// error
      }
    }

    Usage:

     <a href="" onclick="openSubreddit('foo')">

    The login function is used to send the login information to the extension script. It will color the inputs red if there is missing information.

    Code:

    \// log the user into reddit
      function login() {
        let username = document.getElementById('username').value;
        let password = document.getElementById('password').value;
        if(username.trim().length != 0 && password.trim().length != 0) {
          let args = [];
          args.push(username);
          args.push(password);
          handleMessageSending('login', 'home', args);
        } else {
          document.getElementById('username').style.color = "red";
          document.getElementById('password').style.color = "red";
        }
      }

    Usage:

     <a onclick="login()"></a>

    The function resetError is used to reset the styling for incorrect login input.

    Code:

    \// reset the error colors of the login
      function resetError() {
        document.getElementById('username').style.color = "inherit";
        document.getElementById('password').style.color = "inherit";
      }

    Usage:

     <input onfocus="resetError()">

    The function expandElement is used to change the display style of a given element to make it appear or disappear. It is used used to unhide/hide media and comments.

    • id: The id of the element to be expanded. E.g. if the element with the id foo should be hidden/unhidden the id is foo.

    Code:

    \// switches between display:none and display:inherit
    function expandElement(id) {
      element = document.getElementById(id);
      if(element.style.display === "none") {
        element.style.display = "inherit";
      } else {
        element.style.display = "none";
      }
    }

    Usage:

     <a href="" onclick="expandElement('foo')">

    The function scrollTop is used to set the scroll-level of the webview to zero. If this isn't done the webview would stay on the same level after changing views.

    Code:

    \// called on body load
    \// scrolls to top
    function scrollTop() {
      document.body.scrollTop = document.documentElement.scrollTop = 0;
    }

    Usage:

     <body onload="scrollTop()">

    The function checkKey checks a keyup event for the keycode and fires the action of the element if the pressed key is enter.

    Code:

    \// checks if enter is pressed
     function checkKey(element) {
       if(event.keyCode === 13) {
         switch(element){
           case "search":
               executeSearch('home');
               break;
           case "open":
               openSubreddit('home');
               break;
           case "login":
               login();
               break;
           default:
               break;
         }
       }
     }

    Usage:

     <input onkeyup="checkKey('foo')">

    Returns string

search

  • search(): string
  • The search function returns the HTML string of the section to search for subreddits and articles. It needs to contain an element to fire the executeSearch function and an input element with the id searchQuery.

    • executeSearch element example:

      <a onclick="executeSearch('foo')">
    • searchQuery input example:

      <input id="searchQuery">

    Javascript example:

    search("____________");

    Returns string

sort

  • The sort function returns the HTML string of the section to sort the current view by its sort types. The sort names need to fire the corresponding sort command. E.g. sort1 fires the command sort1.

    • Sort command example:
      <a onclick="handleMessageSending('sort1', view, args)">

    Javascript example:

     const sort = require( "sort1", "sort2", "sort3" );

    Parameters

    Returns string

subredditSearch

  • The subredditSearch function returns the HTML string of the subreddit search section. The subreddit names need to send the subreddit command to the extension.

    • Subreddit command example:
      <a onclick="handleMessageSending('subreddit', view, ['subreddit1'])">

    Javascript example:

    const subs = {
     "GetMotivated": params,
     "blaReddit": params,
    }

    Parameters

    Returns string

tail

  • tail(): string
  • The tail function returns the tail of the HTML string. It closes the body and html tag.

     </body>
     </html>

    Returns string

time

  • The time function returns the HTML string of the section to set the interval of the current view. The time names need to fire the corresponding time command. E.g. time1 fires the command time1.

    • Time command example:
      <a onclick="handleMessageSending('time1', view, args)">

    Javascript example:

     const time = require( "time1", "time2", "time3" );

    Parameters

    Returns string

trend

  • The trend function returns the HTML string of the section to browse the currently trending subreddits. The names need to fire the subreddit command to the extension and contain its name in the args param.

    • Subreddit command example:
      <a onclick="handleMessageSending('subreddit', view, ['subreddit'])">

    Javascript example:

    let trends = [ "trend1", "trend2", "trend3" ];

    Parameters

    Returns string

userAbout

  • The userAbout function returns the HTML string of the users information section. It should display the karma, submitted_karma and comment_karma.

    Javascript example:

    let splittedData = data.split(",");
    let karma = splittedData[3242];
    let posts = splittedData[213];
    let comments = splittedData[2900];

    Parameters

    Returns string